好的,我使用了这种串流技术,以便从.txt文件中提取类型、日期、分数等对象,并在稍后的代码中将其推回到向量中。我的问题是,输入文件中的日期是YYYY/MM/DD格式,我需要将其转换为MM/DD/YYYY,但我不熟悉如何做到这一点。有人告诉我使用子字符串方法是可行的,但我是C++的新手,所以有人知道如何解决我的这个问题吗?
void LineData :: Set_Line (const string s)
{
stringstream temp (s);
temp >> type;
temp >> date;
string max;
temp >> max;
max_score = atoi (max.c_str());
string actual;
temp >> actual;
actual_score = atof (actual.c_str());
ws(temp);
getline(temp, name);
}发布于 2013-10-14 10:40:34
这是可以做到的一种方法:
//this will split-up the string
int i = 0;
stringstream ssdate(date); //date needs to be stringstream
while (getline(ssdate, part, '/'))
{
if(i == 0) year = part;
if(i == 1) month = part;
if(i == 2) day = part;
i++; //counter
}
//now all you have to do is arrage them how you need them
//If you want me to show you that I canhttps://stackoverflow.com/questions/19352197
复制相似问题