VC++ (main.cpp):
#include "stdafx.h" #include <iostream> #include <fstream> //ifstream #include <sstream> //getline using namespace std; int main(const int argc, char *argv[]) { /*int i = 0; cout << "argc: " << argc << endl; for(i=0;i<argc;i++) { cout << "*argv[" << i << "]: " << argv[i] << endl; }*/ //Path Convert char pathChar[1024]; string pathString = ""; strcpy(pathChar, argv[1]); //Pointer to Char pathString.assign(pathChar); //Char to String //ReadFile string lines = ""; ifstream File(pathString); if (File.is_open()) //Check File { while(File.good()) { getline(File, lines); cout << lines << endl; } File.close(); } system("pause"); return 0; }Batch (Start.bat):
說明:
將檔案拖曳至exe執行檔,並藉由argc、argv取得路徑,轉換路徑變數型態後進行讀檔動作。
Batch檔是用來測試多行參數的讀取,須放在與執行檔相同之目錄。
沒有留言:
張貼留言