C++ C+中的输入和输出+;
当我在程序中键入输入时,我很难运行这段C++代码。计算机会输出“0”,而不是预期的输出C++ C+中的输入和输出+;,c++,C++,当我在程序中键入输入时,我很难运行这段C++代码。计算机会输出“0”,而不是预期的输出 #include <iostream> using namespace std; int main() { int name; cout << "Enter your name"; cin >> name; cout << "That name fits you well, " << name;
#include <iostream>
using namespace std;
int main()
{
int name;
cout << "Enter your name";
cin >> name;
cout << "That name fits you well, " << name;
return 0;
}
#包括
使用名称空间std;
int main()
{
int名称;
姓名;
cout将您的name变量从int声明为string
std::string name;
cout << "Enter your name";
cin >> name;
cout << "That name fits you well, " << name;
return 0;
std::字符串名称;
姓名;
无法将数据类型从int更改为string您将获得所需的输出您能给我一个示例吗我想知道为什么要使用int
类型的变量来保存名称。您还必须包含标题
。