C++字符串作为参数的传递
1.c++ 有两种风格的字符串形式
1)char a[]={'h','e','l','l','o','\0'}  或者  char a[]="hello"; //C++ 编译器会在初始化数组时,⾃动把 '\0' 放在字符串的末尾;长度:strlrn(a); 2)  string a="hello";
输出:cout<<a或者for(int i=0;i<strlen(a);i++)  cout<<a[i](或者a.at(i) );长度:a.size();
2.字符串作为参数传⼊函数的两种⽅法
#include <iostream>
#include <string>
using namespace std;
int getFilePath(char *str_test1,const string& str_test2)
{
cout<< str_test1<<endl;
printf("%s",str_test2.c_str());
}
int main ()
{
char str_test1[] = "测试路径1";
string str_test2 = "测试路径2\n";字符串函数传参
getFilePath(str_test1,str_test2);
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。