我有一个将信息输出到类中的文件。具体来说,我试图输出的字符串之一将进入一个向量。问题是我试图采用一个字符串(在这种情况下),它将被格式化:
interest_string = "food, exercise, stuff"
所以基本上我想把上面的字符串变成一个数组字符串,或者以某种方式将上面的字符串复制到由逗号分隔符分隔的每个单独字符串中的向量中。
void Client::readClients() {
string line;
while (getline( this->clients, line ))
{
string interest_num_string, interest_string;
istringstream clients( line );
getline( clients, this->sex, ' ' );
getline( clients, this->name, ',' );
getline( clients, this->phone, ' ' );
getline( clients, interest_num_string, ' ' );
getline( clients, interest_string, '.' );
this->interests = atoi(interest_num_string.c_str());
cout << this->sex << "\n" << this->name << "\n" << this->phone << "\n" << interest_num_string << "\n" << interest_string;
}
this->clients.close();
}