c++程序—字符串
- C风格字符串:char 变量名[ ]="字符串值 "
int main() { char str[] = "hello world!"; cout << str << endl; system("pause"); return 0; }
2. C++风格的字符串:string 变量名 = “字符串值”
- NB:要加一个头文件:
#include<string>
#include<iostream> using namespace std; #include<string> int main() { string str = "hello world!"; cout << str << endl; system("pause"); return 0; }