开发者

cygwin doesnt recognize >> operator? C++

cout and the << oper开发者_开发百科ator 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;
}


Ok, now we see the problem. You shouldn't use endl with cin.

Say just cin >> numAlter; and it will automatically wait for the enter key to be pressed.

You don't need both using namespace std; and using 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:

#include <iostream>
using std::cout;

Add the following line:

using std::cin;

and then you will be able to use cin without writing the qualified name (std::cin).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜