作用:用于表示一串字符
两种风格
C风格字符串: char 变量名[] = "字符串值"
char 变量名[] = "字符串值"
示例:
int main() { char str1[] = "hello world"; cout << str1 << endl; system("pause"); return 0; }
C风格的字符串要用双引号括起来
C++风格字符串: string 变量名 = "字符串值"
string 变量名 = "字符串值"
int main() { string str = "hello world"; cout << str << endl; system("pause"); return 0; }
C++风格字符串,需要加入头文件 #include<string>
最后更新于4年前
这有帮助吗?