Strings are used for storing text.
A string
variable contains a collection of characters surrounded by double quotes:
Create a variable of type string
and assign it a value:
string greeting = "Hello";
To use strings, you must include an additional header file in the source code, the <string>
library:
// Include the string library
#include <string>
// Create a string variable
string greeting = "Hello";
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!