【发布时间】:2014-04-17 08:54:43
【问题描述】:
所以我有这个构造函数
A::A(std::istream& is)
{
if (validation(is))
{
std::string line[SIZE];
unsigned int i = 0;
while((std::getline (is, line[i])&& i < SIZE))
{
i++;
}
....
验证看起来像这样,它将 IS 存储在行中并进行一些测试并返回一个布尔值。 它工作得很好,但是这个构造函数中的第二个 getline 是空白的(没有存储在行中)。 如果我注释掉验证,它工作得很好。 所以我想这与getline和buffer有关。我试图清除,但我不擅长流。
如果有人猜到了,谢谢!
主要
ifstream myfile("file.txt");
A a(myfile);
验证.cpp
bool validation(std::istream& is)
{
string line[SIZE];
unsigned int i = 0;
bool valide = false;
while((std::getline(is, line[i])&& i < SIZE))
{
i++;
}
....
【问题讨论】:
标签: c++ file buffer getline istream