我的获取热线无法得到答案
My getline couldn't get the answer
- 起初,一切都很好,直到我以正确的顺序添加 for 函数。
- 当我尝试反转它时,我正确pre_dates所有输出,但其他输出完全错误。
- 如何识别字符串中的单词?
我的产出(2012(:
平均最低温度 : 0 C
平均最高温度 : 0 C
总降雨量 : 1.28
报告的天气情况为: 清除1875655169 雨 0 雪 18
`string thedate, type, line;
int pre_date, ClearDays, SnowyDays, RainyDays;
double lowTemp = 0, highTemp = 0, totalrain = 0, avg_max = 0, avg_min = 0;
system("cls");
ifstream myfile("weather.txt");
if(!myfile.is_open())
{
cout <<"Error opening file.";
}
else
{
for(int i =0; i<4; i++)
{
while(myfile >> pre_date >> thedate >> type >> lowTemp
>> highTemp >> totalrain)
{
double avg_min = lowTemp++;
double avg_max = highTemp++;
getline(myfile, line);
if (line==" ") //error checking
{
cout << " Error" << endl;
ClearDays=0; //if not true
RainyDays=0;
SnowyDays=0;
}
else
{
ClearDays++;
RainyDays++;
SnowyDays++;
totalrain++;
}
}
cout <<"Year: " <<pre_date<< endl;
pre_date++;
cout <<"t Avg. minimum temperature: " <<avg_min<<" C" <<endl;
cout <<"t Avg. maximum temperature: " <<avg_max<<" C" <<endl;
cout <<"t Total rainfall: " <<totalrain<< endl;
cout <<"t Days where reported weather is: " << endl;
cout <<"tt Clear "<<ClearDays<<endl;
cout <<"tt Rain "<<RainyDays<<endl;
cout <<"tt Snow "<<SnowyDays<<endl;
}
}`
通常情况下,如果您使用的是重复的getline运算符,则可能需要清除cin缓冲区,因为它可能已从您之前的条目中遗留下来的数据
使用 :"cin.rdbuf((->in_avail((" 语句来解决此问题,看看它是否有效。
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 使用指针从C++中的数组中获取最大值
- 如何获取std::result_of函数的返回类型
- 欧拉项目#8答案是大以获得有效答案
- 如何在openssl-ecc中获取十六进制格式的私钥
- 使用Unreal C++获取VR耳机的世界位置/方向
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 从C字符串中获取奇怪的字符串长度
- 首要问题的答案让值班员搞错了
- 为什么我的for循环不能正确获取argv
- 从python中调用C++函数并获取返回值
- 如何获取一个数字的前3位
- 获取字符串的长度并将其分配给数组
- 函数从指针 c++ 中获取错误的值并返回错误的答案
- 用于获取以元音和辅音开头的单词数量的程序返回错误的答案
- 在C 中获取错误的答案
- 获取热线(CIN,答案5);在我的程序结束时不起作用
- 我的获取热线无法得到答案