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