C++ 的 字符串变量

等级 291 次按键

把名字存入string、年龄存入int,再用<<连接起来,输出“Alice is 25 years old”。

C++ 代码

// string是保存文本的类型,这里把"Alice"存入name
1string name = "Alice";
// 将年龄25存入int变量age
2int age = 25;
// 每个<<把下一段文本或数字依次送到cout
// 在一行中输出“Alice is 25 years old”
3cout << name << " is " << age << " years old" << endl;

运行结果

Alice is 25 years old
用这段代码练习打字

可以用这段代码练习打字。成绩不会计入排行榜。

这段代码中的符号

这段 C++ 代码中需要输入的符号及其出现次数。

  • <× 10
  • "× 6
  • ;× 3
  • =× 2

C++ 等级 2 的更多代码示例

← 返回 C++ 打字练习