我一直在掙扎超過3小時,但找不到解決方案。 一個簡單的HelloWorld程序是很好的運行,我可以得到輸出,致命錯誤:字符串:沒有這樣的文件或目錄編譯終止
#include<iostream>
#include<string>
using namespace std;
int main(){
string s;
cout<<"hello world";
}
But for the My Sudoku Project I have the following user defined header files, SudokuSolver.h, Matrix.h, Cell.h, Pos.h, Error.h, Exception.h and their corresponding .cpp files.
And
ExampleProgram.cpp
uses these header files, to solve a Sudoku.
(所有的.h和.cpp文件處於同一個文件夾。)
我已經包括using namespace std;
和我將字符串包含爲#include <string>
。在每個頭文件中,我使用string.h的地方都是 。但是,即使我得到了fatal error: string: No such file or directory compilation terminated.
當我作爲
運行G ++ ExampleProgram.cpp SudokuSolver.h Cell.h Error.h Pos.h Matrix.h
當我編譯ExampleProgram.cpp爲
g++ -c ExampleProgram.cpp SudokuSolver.h
Cell.h Error.h Pos.h Matrix.h
我沒有收到任何錯誤。
當我運行ExampleProgram.cpp使用./a.out
我沒有得到我的數獨求解器的輸出。相反,我得到了我以前運行的helloworld程序的輸出。它顯示我的ExampleProgram.cpp
未成功編譯。但如前所述
g++ -c ExampleProgram.cpp SudokuSolver.h
Cell.h Error.h Pos.h Matrix.h
不會給出任何錯誤。
這是我的輸出:
所有的[[email protected] SudokuSolver]$ g++ -c Error.h
[[email protected] SudokuSolver]$ g++ -c Exception.h
[[email protected] SudokuSolver]$ g++ -c Matrix.h
[[email protected] SudokuSolver]$ g++ -c Cell.h
[[email protected] SudokuSolver]$ g++ -c Pos.h
[[email protected] SudokuSolver]$ g++ -c SudokuSolver.h
[[email protected] SudokuSolver]$ g++ -c ExampleProgram.cpp SudokuSolver.h Excepti
on.h Cell.h Error.h Pos.h Matrix.h
[[email protected] SudokuSolver]$ ./a.out
hello world[[email protected] SudokuSolver]$
您不編譯頭文件。 – trojanfoe 2012-02-03 10:22:22
@trojanfoe我已經編譯過了。 – 2012-02-03 10:23:36
@EAGER_STUDENT不,實際上你永遠不會編譯頭文件。當你編譯(實際上在預處理階段)一個.cpp文件時,它包含使用include語句。 – 2012-02-03 10:29:17