我的格式有一个文件: 名字,中间名,姓氏,少校,市,州,GPAC++读文件,忽略逗号和数据输出到屏幕
我想读该文件并将没有逗号的数据输出到屏幕上。这是我到目前为止,但只输出GPA的:
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main(){
string fileline;
string word;
ifstream studentData;
studentData.open("studentData.csv");
while(studentData){
getline(studentData,fileline);
istringstream ss(fileline);
while(getline(ss, word,','));{
cout << word << '\n';
}
}
return(0);
}
在'while'中使用'getline'。你做了第二次(虽然留了一个';'),但不是第一个循环。 –