Эти темы НЕ отвечают мне:
сброс строкового потока
Как очистить переменную строкового потока?
std::ifstream file( szFIleName_p );
if( !file ) return false;
// create a string stream for parsing
std::stringstream szBuffer;
std::string szLine; // current line
std::string szKeyWord; // first word on the line identifying what data it contains
while( !file.eof()){
// read line by line
std::getline(file, szLine);
// ignore empty lines
if(szLine == "") continue;
szBuffer.str("");
szBuffer.str(szLine);
szBuffer>>szKeyWord;
szKeyword всегда будет содержать первое слово, szBuffer не сбрасывается. Я нигде не могу найти четкий пример использования строкового потока.
Новый код после ответа:
...
szBuffer.str(szLine);
szBuffer.clear();
szBuffer>>szKeyWord;
...
Хорошо, это моя окончательная версия:
std::string szLine; // current line
std::string szKeyWord; // first word on the line identifying what data it contains
// read line by line
while( std::getline(file, szLine) ){
// ignore empty lines
if(szLine == "") continue;
// create a string stream for parsing
std::istringstream szBuffer(szLine);
szBuffer>>szKeyWord;
Подробнее здесь: https://stackoverflow.com/questions/121 ... ringstream