[英]fstream behaving weirdly
我是 c++ 的新手,但這太荒謬了!
// fstream output;
// string func();
// both have proven to be working somewhat properly, as I got something already
// written correctly in the output file and I tested func() in the cout
output << func(); // func() returns a string;
我寫在文件中:
// literally nothing
但是當我這樣做時
output << "what the hell" << endl;
output << func();
我明白了
what the hell
{// expected output}
what the hell
{// expected output}
...
what the hell
// last output still missing
我不知道可能是什么問題,在這一點上,我確信該程序只是為了惹惱我。
編輯:
string func()
{
return "test\n";
}
我也剛發現只要手動往output里面放東西到最后什么都會寫,像這樣:
for(int=0; i<4; i++)
{
output << func();
}
output << endl;
找我
test
test
test
test
// func line
// endl line
正如 One Man Monkey Squad 評論的那樣,這只是不沖洗 fstream 的問題。
string func()
{
return "test"
}
output << func() << endl;
給我想要的output,最后沒有多余的線,超出正常的新線
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.