C++ 从文件读取一行,存入一个字符串数组中

C++ 从文件读取一行,存入一个字符串数组中,然后将每个字符串按逗号分离存在一个字符串数组中
如:
word,123,hello
welcome,thanks,90
...
得到的结果是每一行都是这样的数组 , str ={"word","123","hello"},菜鸟求助

1)从文件读取一行:

ifstream infile;
infile.open("文件名.txt");
if (!infile) {
cerr << "error: unable to open input file !!!" << endl;
system("pause");
}
string str;
while (getline(infile, str)) {
// 一行一行读
....
}
2)将每个字符串按逗号分离存在一个字符串数组中
设临时变量,遍历一遍,遇逗号进行处理
PS:
刚开始弄,可能会遇到各种问题,但坚持一下迟早会解决的。。。一起加油。。。(同为菜鸟)
温馨提示:答案为网友推荐,仅供参考
相似回答