简体   繁体   English

使编译器在Notepad ++中工作

[英]Getting compiler to work in Notepad++

I'm having some trouble using Notepad++ to compile code. 使用Notepad ++编译代码时遇到麻烦。 I've installed notepad++ (and NppExec), downloaded MinGW from this source ( http://nuwen.net/mingw.html ) and installed it to "C:\\MinGW\\". 我已经安装了notepad ++(和NppExec),从此源( http://nuwen.net/mingw.html )下载了MinGW,并将其安装到“ C:\\ MinGW \\”。

Then I tried to set notepad++ to use g++ to compile c++. 然后,我尝试将notepad ++设置为使用g ++编译c ++。 Per advice, I entered the following into NppExec's console: 根据建议,我在NppExec的控制台中输入了以下内容:

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

Saved it as C++ Compiler, and added it to the "Macros" section of the toolbar. 将其保存为C ++编译器,并将其添加到工具栏的“宏”部分。

Then I tried to run a simple test program: 然后,我尝试运行一个简单的测试程序:

#include <iostream>

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

After that a couple of weird errors popped up. 之后,出现了一些奇怪的错误。 First it wanted me to save to System32 by default, which I don't remember it doing before (it won't let me, forcing me to save in Documents). 首先,它要我默认保存到System32,这是我以前不记得的事情(它不会让我保存,迫使我保存在Documents中)。

I let it save to documents, than tried to run it with the compiler. 我让它保存到文档中,而不是尝试使用编译器运行它。 It gives me this error, which I don't recognize at all: 它给了我这个错误,我根本不认识:

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)

Please help. 请帮忙。

There is nothing wrong with your compiler. 您的编译器没有错。 You are not using the correct namespace to use cout 您没有使用正确的名称空间来使用cout

#include <iostream>

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

Or 要么

#include <iostream>
using namespace std;

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

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

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