我一直试图做的是...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