2014-07-21 31 views
1

我在使用Notepad ++編譯代碼時遇到了一些麻煩。我安裝了notepad ++(和NppExec),從這個源代碼下載了MinGW(http://nuwen.net/mingw.html),並將它安裝到「C:\ MinGW \」中。使編譯器在Notepad ++中工作

然後我試着設置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默認情況下,我不記得它以前做過(它不會讓我,迫使我保存在文檔中)。

我讓它保存到文檔,比試圖用編譯器運行它。它給了我這個錯誤,我根本不知道:

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) 

請幫助。

回答

4

你的編譯器沒有問題。您未使用正確的命名空間使用cout

#include <iostream> 

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

或者

#include <iostream> 
using namespace std; 

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