简体   繁体   English

C ++:无法解析标识符cout,Netbeans,Ubuntu

[英]C++: Unable to resolve identifier cout, Netbeans, Ubuntu

I am using C++ on Netbeans 7.1 on Ubuntu 11.04. 我在Ubuntu 11.04上的Netbeans 7.1上使用C ++。 For some reason, the following code results in the error message "Unable to resolve identifier cout". 由于某种原因,以下代码导致错误消息“无法解析标识符cout”。

#include <iostream>

using namespace std;
int main()
{
    std::cout << "Hello,world!\n";
    return 0;
}

Any help resolving this problem would be greatly appreciated. 任何帮助解决这个问题将不胜感激。

The solution for your problem is at least strange ;) Once iostream header is added, one has to reparse code. 你的问题的解决方案至少是奇怪的;)一旦添加了iostream头,就必须重新解析代码。 Click right on a project, go to code assistance and click to reparse project. 单击项目右键,转到代码帮助,然后单击以重新分析项目。 Worked for me. 为我工作。 I was using netbeans for mac. 我正在使用netbeans for mac。

What sort of file is this in? 这是什么类型的文件? Is it a .h file, or .hpp file? 它是.h文件还是.hpp文件? I had this same issue. 我有同样的问题。 Netbeans can be ridiculous sometimes with C++. Netbeans有时候用C ++会很荒谬。 For me, I changed #include <iostream> to #include<iostream.h> 对我来说,我将#include <iostream>更改为#include<iostream.h>

This may seem too simple, but... 这似乎太简单了,但......

In my NetBeans installation, when I go to create a new project, specify C/C++, it brings up a dialog box prompting for "Project Name:", location, folder, makefile name, and then... a check box for "Create Main File", an edit box with "main" filled in, and to the right of that is a drop down list that reads "C". 在我的NetBeans安装中,当我去创建一个新项目时,指定C / C ++,它会弹出一个对话框,提示“项目名称:”,位置,文件夹,生成文件名,然后......“复选框” “创建主文件”,一个填充了“main”的编辑框,右边是一个读取“C”的下拉列表。 If you hit Finish, this will create "main.c" (C, but NOT a C++ file). 如果你点击完成,这将创建“main.c”(C,但不是C ++文件)。 Instead, in the drop down list, select "C++". 而是在下拉列表中选择“C ++”。 Then the IDE creates main.cpp, which will be compiled with g++ and will find those includes and functions. 然后IDE创建main.cpp,它将使用g ++编译,并将找到那些包含和函数。

There is a difference between std::cout and cout. std :: cout和cout之间存在差异。 You don't currently have std::cout defined in your file. 您当前没有在文件中定义std :: cout。 std::cout is ac standard out. std :: cout是交流标准。 In C++ we only need cout to work with iostream. 在C ++中,我们只需要cout来使用iostream。

If you must use a standard c out then do the following: 如果必须使用标准c out,请执行以下操作:

Add this to the top under iostream 将此添加到iostream下的顶部

#include <iostream> //Input output stream in C++
#include <cstdlib> //Stands for c standard library
using namespace std; 

Your code will now work because: This change defines std::cout and std::cin among other things. 您的代码现在可以正常工作,因为:此更改定义了std :: cout和std :: cin等。 (standard in, standard out respectively.) (标准输入,标准输出。)

However, I'd recommend this alternative if you don't need standard in outs: Replace std::cout with cout, because cout is defined in iostream in C++. 但是,如果您不需要标准输出,我建议使用此替代方法:用cout替换std :: cout,因为cout是在C ++中的iostream中定义的。 Your program would have worked without the std:: portion of your cin cout commands because you originally included iostream. 你的程序可以在没有你的cin cout命令的std ::部分的情况下工作,因为你最初包含了iostream。

check whether iostream is really getting included; 检查iostream是否真的被包括在内; i have tried your code on my machine using eclipse cdt it worked fine.so, please check the includes. 我已经在我的机器上使用eclipse cdt尝试了你的代码它运行正常。所以,请检查包含。

Hey look at your Output Debug. 嘿看看你的输出调试。 You may see "no permission". 你可能会看到“没有许可”。 After I changed the file permission of "/YourProjekt/dist/Debug/GNU-Linux/file" to runable and everyone can read and write the error disappeared. 我将“/ YourProjekt / dist / Debug / GNU-Linux / file”的文件权限更改为可运行后,每个人都可以读写错误消失。 (BTW: I had the bug because I was on a NTFS System with my Projekt, it have to be ext partition) Hope I can help you with that. (顺便说一下:我有这个bug,因为我和我的Projekt在NTFS系统上,它必须是分区)希望我可以帮助你。

Try taking out the using namespace std; 尝试取出using namespace std; - it's generally considered bad form anyway :-) - 无论如何,它通常被认为是糟糕的形式:-)

I'm not sure that will fix the problem but most people either use the namespace or fully qualify things like std::cout . 我不确定这会解决问题,但大多数人要么使用命名空间,要么完全限定std::cout类的东西。 I've never seen code that does both. 我从未见过同时执行这两种操作的代码

The other thing to check is that the iostream header actually is being bought in. In other words, are there any errors on that line. 要检查的另一件事是iostream标题实际上正在被买入。换句话说,该行是否有任何错误。 A lot of problems (at least in the Windows world, so it may not necessarily apply to you) seem to be due to faulty path setup in NetBeans. 很多问题(至少在Windows世界中,所以它可能不一定适用于您)似乎是由于NetBeans中的错误路径设置。

尝试取出cout旁边的std ::

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM