使用以下声明调用函数的最佳方式是什么
string Extract(const char* pattern,const char* input);
我用
string str=Extract("something","input text");
这个用法有问题吗
我应该使用以下吗
char pattern[]="something";
char input[]="input";
//or use pointers with new operator and copy then free?
两者都有效,但我喜欢第一个,但我想知道最佳实践。
最佳答案
文字字符串(例如 "something"
)作为函数调用的 const char*
参数可以正常工作。
关于c++ 使用 const char* 参数类型调用函数的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9353531/