Merge branch 'master' of github.com:vishap/test
This commit is contained in:
77
cpp/stl/istringstream_fail_eof.cpp
Normal file
77
cpp/stl/istringstream_fail_eof.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/* Check cf5-opt.vim defs.
|
||||
-VIM-: let g:lcppflags="-std=c++11 -O2 -pthread"
|
||||
VIM: let g:wcppflags="/O2 /EHsc /DWIN32"
|
||||
VIM: let g:argv=""
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <exception>
|
||||
|
||||
void test( const std::string& str_to_parse )
|
||||
{
|
||||
std::stringstream ss(str_to_parse);
|
||||
std::string str;
|
||||
int v;
|
||||
ss >> str >> v;
|
||||
|
||||
std::cout << "str=\"" << str_to_parse << '"' <<std::endl
|
||||
<< "good()=" << ss.good()
|
||||
<< " fail()=" << ss.fail()
|
||||
<< " bad()=" << ss.bad()
|
||||
<< " eof()=" << ss.eof()
|
||||
<< std::endl << std::endl;
|
||||
}
|
||||
|
||||
void test2( const std::string& str_to_parse )
|
||||
{
|
||||
std::stringstream ss(str_to_parse);
|
||||
std::string str;
|
||||
std::string str2;
|
||||
int v;
|
||||
ss >> str >> v;
|
||||
|
||||
if ( ss.fail() && !ss.eof() )
|
||||
{
|
||||
ss.clear();
|
||||
ss >> str2;
|
||||
}
|
||||
|
||||
std::cout << "str=\"" << str_to_parse << '"' <<std::endl
|
||||
<< "str2=\"" << str2 << '"' <<std::endl
|
||||
<< "good()=" << ss.good()
|
||||
<< " fail()=" << ss.fail()
|
||||
<< " bad()=" << ss.bad()
|
||||
<< " eof()=" << ss.eof()
|
||||
<< std::endl << std::endl;
|
||||
}
|
||||
|
||||
int main ( void )
|
||||
{try{
|
||||
test("string 1234");
|
||||
test("string 1234 ");
|
||||
test("string 1234 12");
|
||||
test("string ");
|
||||
test("string");
|
||||
test("string aaaa");
|
||||
test("string aaaa ");
|
||||
|
||||
test2("sss tttt");
|
||||
test2("sss tttt ");
|
||||
test2("sss 3456tttt");
|
||||
test2("sss");
|
||||
test2("sss ");
|
||||
return 0;
|
||||
}
|
||||
catch ( const std::exception& e )
|
||||
{
|
||||
std::cerr << std::endl
|
||||
<< "std::exception(\"" << e.what() << "\")." << std::endl;
|
||||
return 2;
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
std::cerr << std::endl
|
||||
<< "unknown exception." << std::endl;
|
||||
return 1;
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user