初始值未按预期显示

时间:2017-01-09 15:50:14

标签: c++ int

他的书使用C ++的原则和实践中的第一个Stroustrup例子之一如下:

// read name and age (2nd version)
int main()
{
          cout << "Please enter your first name and age\n";
          string first_name = "???";      // string variable
                                                            // ("???” means “don’t know the name”)
          int age = –1;         // integer variable (–1 means “don’t know the age”)
          cin >> first_name >> age;      // read a string followed by an integer
          cout << "Hello, " << first_name << " (age " << age << ")\n";
}

这本书说通过输入 22 Carlos 我会得到输出你好,22(年龄-1),但是,独立于初始值我总是得到零

ps:除此之外,程序按预期工作。

0 个答案:

没有答案