« first day  last day (14 days later) » 

7:25 AM
did you manage to solve your problem? If not, contact me here and we'll figure it out together.
 
 
4 hours later…
11:13 AM
no still waiting pls help
 
sure
you here?
@RohiniSingh seems the conversation is asynchronous: so..lets give it a try this way:
firstly.. getline doesn't throw eof exception, it sets the eof bit and failbit to 1
it throws basic_ios::clear (iostream error)
secondly, can you be more precise regarding " In catch block i check and skip if exception is because of eof but its not good.

please suggest how can i skip eof exception in below code"
 
 
1 hour later…
12:30 PM
I just want to set failbit to 0 when getline read eof
 
1:18 PM
unfortunately, this is not possible. Getline will set both eofbit and failbit because it has reached the end of file (eof) and the desired character couldn't be retrieved(failbit)
are you bound to use getline(..) or can you use some other methods?
or..as @Yes said, disable throwing exception on failbit as the only reason of getline(...) will throw is a eof
 
1:33 PM
No I am not bound to use getline u can suggestion if any o
 
std::ifstream in("test.txt");

if(!in.is_open()) {
std::cout<<"could not open file";
return 1;
}

in.seekg(0, std::ios::end);
std::string strRead;

try {
strRead.reserve(static_cast<unsigned>(in.tellg()));
} catch( const std::length_error &le) {
std::cout<<"could not reserve space for file"<<le.what()<<std::endl;
return 1;
} catch(const std::bad_alloc &bae) {
std::cout<<"could not allocate space for file content"<<bae.what()<<std::endl;
return 1;
} catch(...) {
std::cout<<"other exception occurred while reserving space for file content"<<std::endl;
try this, return 1 means error(I have written the sample in main)
this will read all the content of the file in strRead at once
 
thanks Cristan could you please put this as answer coz I am good with this
 
sure
done
 
ok thanks I accept
 
1:49 PM
Happy to help you, have a nice day
 
:-) thnx
 

« first day  last day (14 days later) »