1
閱讀次數我有這樣的程序:C++從文件
#include <iostream>
#include <fstream>
using namespace std;
int main (int argc, char** argv)
{
ifstream infile("argv[1]");
int testNumber = 0;
infile >> testNumber;
cout << testNumber << '\n';
}
我用這個命令運行./program myfile.txt
myfile.txt
包含空格和換行
我期望分離一些整數該程序輸出文件中的第一個數字,但它總是打印0
。我究竟做錯了什麼?
我現在覺得很愚蠢 –