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;
}
最佳答案
好的,现在我们看到问题了。你不应该使用 endl
与 cin
.
只说cin >> numAlter;
它将自动等待按下回车键。
你不需要两者 using namespace std;
和 using std::cin;
.那只是一个大胆的猜测,因为在没有看到代码的情况下我无法确定您的问题。
<罢工> 我的 Crystal 球说你的程序开始于:
#include <iostream>
using std::cout;
添加以下行:
using std::cin;
然后你就可以使用cin
了不写限定名称( std::cin
)。
罢工>
关于c++ - cygwin 不识别 >> 运算符? C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4927956/