cygwin 无法识别>>操作员? C++
cout 和 <<运算符在 CYgwin 中编译 C++ 程序时工作正常,但一旦我尝试 cin >>运算符,编译器中断说 cygwin 无法识别 >>?这是关于什么的? 源代码:
#include "TenStrings.h"
#include <iostream>
using namespace std;
using std::cin;
//Default Constructor
TenStrings::TenStrings()
{
int ithElement;
strings[0] = "String 1";
strings[1] = "String 2";
strings[2] = "String 3";
strings[3] = "String 4";
strings[4] = "String 5";
strings[5] = "String 6";
strings[6] = "String 7";
strings[7] = "String 8";
strings[8] = "String 9";
strings[9] = "String 10";
cout << "Enter how many strings you would like to alter: " << endl;
int numAlter;
cin >> numAlter >> endl;
//cin >> "Enter which string to change: " << ithElement << endl;
cout << strings[0] << endl;
cout << strings[3] << endl;
}
cout and the << operator work fine in compiling c++ program in CYgwin but as soon as i try the cin >> operator, compiler breaks says cygwin doesnt recognize >>? wt is that about?
source code:
#include "TenStrings.h"
#include <iostream>
using namespace std;
using std::cin;
//Default Constructor
TenStrings::TenStrings()
{
int ithElement;
strings[0] = "String 1";
strings[1] = "String 2";
strings[2] = "String 3";
strings[3] = "String 4";
strings[4] = "String 5";
strings[5] = "String 6";
strings[6] = "String 7";
strings[7] = "String 8";
strings[8] = "String 9";
strings[9] = "String 10";
cout << "Enter how many strings you would like to alter: " << endl;
int numAlter;
cin >> numAlter >> endl;
//cin >> "Enter which string to change: " << ithElement << endl;
cout << strings[0] << endl;
cout << strings[3] << endl;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,现在我们看到问题了。您不应将
endl
与cin
一起使用。只是说
cin>> numAlter;
并且它会自动等待按下回车键。您不需要同时使用
using namespace std;
和using std::cin;
。这只是一个疯狂的猜测,因为在没有看到代码的情况下我无法确定你的问题。<罢工>
我的水晶球说你的程序开始于:
添加以下行:
然后你将能够使用cin
而无需编写限定名称 (std::cin )。
Ok, now we see the problem. You shouldn't use
endl
withcin
.Say just
cin >> numAlter;
and it will automatically wait for the enter key to be pressed.You don't need both
using namespace std;
andusing std::cin;
. That was just a wild guess because I couldn't be sure of your problem without seeing the code.My crystal ball says your program starts with:
Add the following line:
and then you will be able to use
cin
without writing the qualified name (std::cin
).