更新时间:2023-11-07 16:59:04
一个简单的方法是使用 std :: stringstream
结合 getline
像这样:
A simple way of doing this is probably using a std::stringstream
in combination with getline
like this:
std::string str;
while (std::getline(fin, str)) // fin is the input stream
{
std::istringstream iss(str);
std::string token;
while (std::getline(iss, token, ',')) // get the token as a std::string
{
// process it here, can use `stoi` to convert to int
}
}