cygwin 无法识别>>操作员? C++

发布于 2024-10-16 11:34:42 字数 915 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌伤浅笑 2024-10-23 11:34:42

好的,现在我们看到问题了。您不应将 endlcin 一起使用。

只是说cin>> numAlter; 并且它会自动等待按下回车键。

您不需要同时使用 using namespace std;using std::cin;。这只是一个疯狂的猜测,因为在没有看到代码的情况下我无法确定你的问题。

<罢工>
我的水晶球说你的程序开始于:

#include <iostream>
using std::cout;

添加以下行:

using std::cin;

然后你将能够使用 cin 而无需编写限定名称 (std::cin )。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文