我有点卡在这个问题上..
头文件* *
#include "Duration.h"
class Track
{
private:
Duration trackTime;
std::string trackTitle;
public:
inline Duration getTrackTime() const;
inline std::string getTrackTitle() const;
Track(Duration d = Duration(0,0,0),std::string trackTitle = "");
};
inline std::string Track::getTrackTitle() const
{
return trackTitle;
}
** ** cpp文件..** * *
using namespace std;
Track::Track(Duration trackTime , string trackTitle)
{
this->trackTitle = trackTitle;
this->trackTime = trackTime;
}
istream& operator>>(istream& is, Track & t)
{
Duration trackTime;
string trackTitle;
char c1;
if (is >> trackTime >> c1 >>trackTitle)
{
if(c1 == '-')
{
t = Track(trackTime,trackTitle);
}
else
{
is.clear(ios_base::failbit);
}
}
return is;
}
** * **主要* ***
int main(int argc, const char * argv[])
{
Track track;
cin >> track;
cout << track <<endl;
}
我只是测试 ostream 是我所期望的。
但是当我输入这样的字符串时。“0:03:30 - 嘿乔(比利罗伯茨)”
它只打印出“0:03:30 - 嘿”
谁能解释为什么这样的打印结果。?以及如何打印出整个曲目标题。?