我想将字符串传递给第二个函数,它填充字符数组并返回值。在第一个函数中,我想在第二个函数填充后获取字符串长度。
第一步
Planning to pass the character array
char data[10]="";
GetData(data); // Here Iam doing memset value to data
strlen(data);
第二步
Planning to pass the character pointer
char *data;
GetData(data); // what I should do
strlen(data);
谁能建议最好的做法
最佳答案
你想使用 std::string
,类似于:
std::string data;
void GetData(std::string& str);
通过非 const
引用允许 GetData
改变 str
。
关于c++ - 将字符传递给其他函数的最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26013111/