我#include
這些標題:ifstream的的<fstream>不會編譯
#include <iostream>
#include <fstream>
但卻這段代碼:
ifstream inFile;
仍然不會編譯。可能是什麼問題呢?我使用Visual Studio 2010,Win32 C++。
我#include
這些標題:ifstream的的<fstream>不會編譯
#include <iostream>
#include <fstream>
但卻這段代碼:
ifstream inFile;
仍然不會編譯。可能是什麼問題呢?我使用Visual Studio 2010,Win32 C++。
您可以將using namespace std;
置於代碼的頂部,因此您不必完全限定標準C++的內容,但它被大量開發人員認爲是不好的形式。
我只是前綴,在標準的東西與std::
,這使得代碼不再:
std::cout << "Hello, world.\n";
但讓我走出困境面對面的人命名空間衝突。
下面的記錄表明在行動中使用的std::
前綴:
$ cat testprog.cpp
#include <iostream>
#include <fstream>
int main (void) {
int n;
std::ifstream inFile("input.txt");
inFile >> n;
std::cout << "File contained " << n << '\n';
return 0;
}
$ cat input.txt
42
$ g++ -Wall -Wextra -o testprog testprog.cpp ; ./testprog
File contained 42
文件包含42 ... :) – 2011-12-28 02:56:18
該類型是std::ifstream
。除非您通過其他方式將限定名稱帶入範圍,否則必須全部寫出。
我完全忘了它。謝謝! – 2011-12-28 02:44:51
**一般的建議:**,我們希望看到一個測試用例知道你做了什麼錯;錯誤信息也不會傷害。下面的答案將是猜測。 – 2011-12-28 02:41:19