#include <iostream> #include <fstream> using namespace std; int main() { string InFile; int SlashNo = 0; string LineData = ""; cout << "Input File Location:"; getline(cin,InFile); for(int i=0; i<InFile.length(); i++) { if(InFile[i] == '\\') { SlashNo++; } } cout << "SlashNo = " << SlashNo << endl; int TotalLength = InFile.length()+SlashNo+1; char RealInputFile[TotalLength]; int jdx =0; for(int i=0; i<InFile.length(); i++) { if(InFile[i] == '\\') { RealInputFile[jdx] = InFile[i]; jdx++; RealInputFile[jdx] = InFile[i]; } else { RealInputFile[jdx] = InFile[i]; } jdx++; } RealInputFile[TotalLength-1] = '\0'; cout << "Current File Location : " << RealInputFile << endl; ifstream Source(RealInputFile,ios::in); if(Source) { cout << "Read Secceeded" << endl; while(!Source.eof()) { getline(Source,LineData); cout << LineData << endl; LineData = ""; } } else { cout << "Read Failed" << endl; } return 0; }
2011/07/13
C++在Widows下指定讀檔路徑
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言