我一直試圖做的是...C++如何通過命令行參數讀取TXT文件
1)讀取由命令行參數txt文件,
2)使用字符串在txt文件中作爲主要方法的參數(或者你需要調用的任何方法)。
例如,有兩個txt文件,其中一個文件名爲character.txt,另一個文件名爲match.txt。
這些文件的內容就是這樣。
character.txt
//This comprises of six rows. Each of the rows has two string values
Goku Saiyan
Gohan Half_Saiyan
Kuririn Human
Piccolo Namekian
Frieza villain
Cell villain
match.txt
//This comprises of three rows, each of them is one string value
Goku Piccolo
Gohan Cell
Kuririn Frieza
如果我使用這些字符串不使用命令行,我會宣佈字符串character.txt這樣。
typedef string name; //e.g. Goku
typedef string type; //e.g. Saiyan, Human, etc
現在我正在尋找如何閱讀和TXT文件像以上這樣的發送字符串值,並使用它們功能的主要方法裏面,像理想的這種方式。
int main(int argc, char *argv)
{
for (int i = 1; i < argc; i++) {
String name = *argv[i]; //e.g. Goku
String type = *argv[i]; //e.g. Saiyan, Human, etc
String match = * argv[i]; //Goku Piccolo
//I don't think any of the statements above would be correct.
//I'm just searching for how to use string values of txt files in such a way
cout << i << " " << endl; //I'd like to show names, types or matchs inside the double quotation mark.
}
}
理想情況下,我想以這種方式調用此方法。
According to this web site.,至少我明白可以在C++中使用命令行參數,但是我找不到更多的信息。如果您對此提出任何建議,我將不勝感激。
PS。我正在使用Windows和代碼塊。
給OP提供一些關於在哪裏檢查錯誤的警告可能是一個好主意。幾個原因:回答完整性和更少「我現在做錯了什麼?」後續問題和意見。 – user4581301