【发布时间】:2019-02-23 21:09:28
【问题描述】:
我有一个结构,其中包含 2 个具有值的字段。我想实现一种更改字段值的方法。我使用以下代码执行此操作,但它不正确。我想问一下如何解决这个问题?
#include <iostream>
using namespace std;
struct CPerson {
const char* name = "Ivan";
const char* gender = "Male";
};
void SetName(const char* szName) {
//what to write here?
*name = *szname;
}
【问题讨论】:
-
请使用
std::string而不是char *。 -
我想,你必须看看 C++ 数据结构。我推荐阅读this博客
-
@G.M.:有时
std::string_view更合适。