我正在Visual Studio 2012中開發一個項目,我無法弄清楚爲什麼這段代碼總是返回「無法打開文件!」,因爲tram.exe和stops.txt在相同的(Debug)文件夾。在C++中讀取文件的開始
#include <iostream>
#include <fstream>
int main (int count, char *arguments[]) {
if (count > 1) {
ifstream input("stops.txt");
if (input.is_open()) {
} else {
cout << "The file can not be opened!";
}
}
}
當您導航到shell中的目錄並在shell中執行此文件時,它在那裏工作嗎? 如果是這樣,你應該a)提供絕對路徑或b)檢查VS的環境變量。 – icbytes