c++ - 让编译器在 Notepad++ 中工作

标签 c++ windows gcc c++11

我在使用 Notepad++ 编译代码时遇到了一些问题。我已经安装了 Notepad++ (和 NppExec),从这个来源(http://nuwen.net/mingw.html)下载了 MinGW 并将其安装到“C:\MinGW\”。

然后我尝试设置notepad++使用g++编译c++。根据建议,我在 NppExec 的控制台中输入了以下内容:

NPP_SAVE
CD $(CURRENT_DIRECTORY)
C:\MinGW\bin\g++.exe -g "$(FILE_NAME)"

将其保存为 C++ 编译器,并将其添加到工具栏的“宏”部分。

然后我尝试运行一个简单的测试程序:

#include <iostream>

int main()
{
cout << "Hello, world!";
}

之后出现了一些奇怪的错误。首先它要我默认保存到 System32,我不记得它以前做过(它不让我,强制我保存在 Documents 中)。

我让它保存到文档中,而不是尝试用编译器运行它。它给了我这个错误,我根本不认识它:

NPP_EXEC: "C++ Compiler"
NPP_SAVE: C:\Users\Bova\Documents\Test.cpp
CD: C:\Users\Bova\Documents
Current directory: C:\Users\Bova\Documents
C:\MinGW\bin\g++.exe -g "Test.cpp"
Process started >>>
Test.cpp: In function 'int main()':
Test.cpp:5:5: error: 'cout' was not declared in this scope
     cout << "Hello, world!";
     ^
Test.cpp:5:5: note: suggested alternative:
In file included from Test.cpp:1:0:
c:\mingw\include\c++\4.8.2\iostream:61:18: note:   'std::cout'
   extern ostream cout;  /// Linked to standard output
              ^
<<< Process finished. (Exit code 1)

请帮忙。

最佳答案

你的编译器没有问题。您没有使用正确的命名空间来使用 cout

#include <iostream>

int main()
{
    std::cout << "Hello, world!";
}

或者

#include <iostream>
using namespace std;

int main()
{
    cout << "Hello, world!";
}

关于c++ - 让编译器在 Notepad++ 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24857059/

相关文章:

c++ - strcat 不刷新

c++ - 使用指针搜索值

c++ - 在不使用 decltype[c++] 的情况下传递键类型的比较函数

windows - DOS 批处理文件 - 显示带有两个选项的弹出消息

windows - windows phone 10模拟器无法启动

c++ - 非命名空间范围错误的显式特化......迫切需要帮助

c - 使用 SDL 应用程序删除控制台窗口

c++ - 将参数作为整数数组传递

python - 从 python 运行和处理外部应用程序

c - Linux 链接一个共享对象