[問題] c++ 如何用string當做讀檔檔名?
遇到的問題: (題意請描述清楚)
我想開啟一個以string為檔名的檔案,我該怎麼做?
--------------------------------------------------------
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string fname; // fname = "testfile"
ifstream fin;
cout << fname; //這裡輸出的話可以得到字串testfile
fin.open(fname);
--------------------------------------------------------
希望得到的正確結果:
可以開啟"testfile"這個檔案
程式跑出來的錯誤結果:
no matching function for call to `std::basic_ifstream<char,
std::char_traits<char> >::open(std::string&)'
開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
g++ -O0 -g3
我記得
fin.open(fname)的fname好像要什麼處理
試過fmane.begin()也沒有用
請大家幫幫忙了 ><
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.37.178.161
※ 編輯: weselyong 來自: 114.37.178.161 (03/21 01:33)
※ 編輯: weselyong 來自: 114.37.178.161 (03/21 01:34)
推
03/21 01:37, , 1F
03/21 01:37, 1F
推
03/21 01:48, , 2F
03/21 01:48, 2F
→
03/21 02:45, , 3F
03/21 02:45, 3F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章