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);


}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2021-07-17
  • 2022-03-06
  • 2022-12-23
  • 2021-12-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-10
  • 2021-09-01
  • 2021-08-26
相关资源
相似解决方案