简体   繁体   中英

Getting compiler to work in Notepad++

I'm having some trouble using Notepad++ to compile code. I've installed notepad++ (and NppExec), downloaded MinGW from this source ( http://nuwen.net/mingw.html ) and installed it to "C:\\MinGW\\".

Then I tried to set notepad++ to use g++ to compile c++. Per advice, I entered the following into NppExec's console:

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.

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

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

#include <iostream>

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

Or

#include <iostream>
using namespace std;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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