C++字符串作为参数的传递

1.c++ 有两种风格的字符串形式
1)char a[]={'h','e','l','l','o',''}  或者  char a[]="hello"; //C++ 编译器会在初始化数组时,自动把 '' 放在字符串的末尾
;长度: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
";
     getFilePath(str_test1,str_test2);


}
原文地址:https://www.cnblogs.com/shierlou-123/p/13554991.html