Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C+中的输入和输出+;_C++ - Fatal编程技术网

C++ C+中的输入和输出+;

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;

当我在程序中键入输入时,我很难运行这段C++代码。计算机会输出“0”,而不是预期的输出

#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
类型的变量来保存名称。您还必须包含标题