In the following code, the second loop does not work once in Xcode, but in Visual Studio it works as it should:
int temp; char symbol; std::ifstream ifs("a.txt"); while (ifs>>temp) cout<<temp<<' '; // перебор последовательности, как чисел. cout<<endl; ifs.seekg(0,ios::beg); // установка курсора в начало файла. ifs.clear(); // очищение флага состояния. while (ifs.get(symbol)) // перебор последовательности, как символов. if (symbol!=' ' && symbol!='\n') cout<<symbol<<' '; ifs.close();
The second cycle does not go through even once when the end of the file is reached in the first cycle. All tests performed indicate a problem with the state flags. But the state flags after the 'clear ()' method are cleared, as it should be. Therefore, I can not deal with this problem. Unsubscribe, please, those who faced this problem?
seekg
andclear
- yrHeTaTeJlb