これらのスレッドは私に答えません:
stringstream 変数をクリアするにはどうすればよいですか?
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
リセットされません。stringstream の使用方法に関する明確な例はどこにも見つかりません。
回答後の新しいコード:
...
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;