【发布时间】:2014-04-20 01:56:27
【问题描述】:
您好,我有一些输入行,按以下顺序:
Date, Time, Price, Volume, Value,
日期格式为 DD/MM/YY 时间格式为 HH/MM/SS AM/PM 价格、数量和价值是用逗号分隔的数字。
此输入有 4000 行,偶尔还有一个共享代码,例如“CX” 或 'NXXT' 将出现在 'value' 逗号之后。
我的程序无法处理并崩溃。
我需要的是一种忽略“值”之后逗号之后的任何内容并继续阅读下一行的方法。这将在“Shares”类中。
这是来自我的课程的输入流:
类:“日期”
istream & operator >> (istream & input, Date & C) /// An input stream for the day, month and year
{
char delim;
input >> C.day >> delim >> C.month >> delim >> C.year;
return input; /// Returning the input value
}
类“时间”
istream & operator >> (istream & input, Time & C) /// An input stream for the hour minutes and seconds
{
char delim;
input >> C.hour >> delim >> C.minute >> delim >> C.second;
getline(input,C.ampm,',');
return input; /// Returning the input value
}
“共享”类
istream & operator >> (istream & input, Shares & C) /// An input stream for the day, month and year
{
char delim;
input >> C.price >> delim >> C.volume >> delim >> C.value >> delim;
return input; /// Returning the input value
}
【问题讨论】:
-
基本上为了让它更简单,我只需要一种方法来停止读取“值”逗号之后的任何内容,例如 250,CX,其中需要跳过“CX”。
-
您能发布一个示例输入行吗? Shares 是一个静态类吗?为什么要将 Shares 作为参数传递给流运算符,而这可能是 Share 对象上的一个方法,该方法获取一行并解析它?