int : redefinition (C++)
int : redefinition (C++)
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int x, y;
int main()
{
cout << "Please give me a number:";
int x = (cin, x);
cout << "Please give me another number:";
int y = (cin, y);
cout << "The sum of " << x;
cout << "and " << y;
cout << "is " << x+y;
}
谁能告诉我为什么(尽管简单)这没有添加?我真的不确定如何返回用户输入的数字和类似的东西。刚开始学这个
我相信,而不是这样:
int x = (cin, x);
你想要这个:
cin >> x;
cin
(console input)的工作方式与cout
(console output)几乎相同,您可以正确使用。
你可能想要更多地了解他们:
- std:: cout
- std:: cin
同样,您不需要在main()
中重新定义x
和y
,因为它们是全局变量。
正确代码为:
#include <iostream> // for cin,cout we use iostream
#include <stdio.h> // you don't need this header file in this program
#include <string> // also you don't need this header
using namespace std;
int main()
{
int x,y;
cout<<"Please give me a number : ";
cin>>x;
cout<<"Please give me another number : ";
cin>>y;
cout<<"The sum of "<<x<<" and "<< y<<" is "<<x+y;
return 0;
}
读Basic_Syntax
相关文章:
- 我收到类中每个方法的"redefinition of"错误
- 头文件出现问题; "redefinition of class"
- 尝试实施 PIMPL idom 时如何避免"redefinition; different basic types"
- G++ 编译器"redefinition…previously defined"
- Typedef redefinition with different types (Emscripten SDL2+O
- C++错误"redefinition of 'string' as different kind of symbol"
- "Typedef redefinition with different types" Clang中关于工作MSVC代码的错误
- C++ "'DOMDocument' : redefinition" Xercesc错误
- C++简单的类程序无法编译。我搞砸了包含标题吗? 'Error redefinition of a class'
- 将 Qt 5.3.1 与 Open Inventor 9.4.1 配合使用时出错 visual2013: C2371: "GLdouble redefinition"
- 使用"auto"关键字时"redefinition"错误更改为"differs in levels of indirection"
- 如何处理"class type redefinition"
- "Error: Redefinition of Class" - 但没有重新声明
- 如何解决类构造函数中的"redefinition of default parameter"
- MSVC错误C2371 "redefinition; different basic types",除了我没有看到我在哪里重新定义任何东西
- 模板类中的静态变量导致 C2371 'redefinition; different basic types'
- VS2010 中的"redefinition; different type modifier"
- C++编译错误"redefinition of",需要帮助才能找到
- int : redefinition (C++)
- "redefinition"是什么意思?