[問題] run-time input string as file name
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Dev-C++
問題(Question):
開啟程式之後輸入檔名
開啟該檔案
餵入的資料(Input):
filename.csv
預期的正確結果(Expected Output):
看到filename.csv
錯誤結果(Wrong Output):
無法開啟該檔案
file open error // 自訂的 error message
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
string inputName;
cout << "input fileName with extension\n? ";
cin >> inputName;
fstream ioFile( inputName.c_str(), ios::in | ios::out );
if( !ioFile )
{
cerr << "file open error" << endl;
system("pause");
exit(1);
}
system("pause");
return 0;
}
inputName.c_str() 是爬文時看到的
但好像沒有用...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.213.175
→
03/12 13:38, , 1F
03/12 13:38, 1F
→
03/12 13:40, , 2F
03/12 13:40, 2F
→
03/12 13:54, , 3F
03/12 13:54, 3F
→
03/12 14:21, , 4F
03/12 14:21, 4F
→
03/12 15:02, , 5F
03/12 15:02, 5F
→
03/12 15:17, , 6F
03/12 15:17, 6F
推
03/12 15:25, , 7F
03/12 15:25, 7F
→
03/12 15:27, , 8F
03/12 15:27, 8F
→
03/12 15:48, , 9F
03/12 15:48, 9F
→
03/12 15:51, , 10F
03/12 15:51, 10F
→
03/12 15:52, , 11F
03/12 15:52, 11F