Is it possible to control the execution status of output operations in C ++ without try - catch blocks?

I am running the cout<<"Smthng" and I want to programmatically find out if this operation was successful. That is, I need something like Paskalevsky IOResult , or some variation of GetLastError() . I thought that there is such a field in ios , but there are only types for catching exceptions.

  • if (cout<<"Smthng") , not? - Abyx
  • one
    So somewhere - if (cout.fail ()) - 0xdb
  • @ 0xdb Thank you, this is an option - DNS

1 answer 1

By default, operations with exception streams are not generated. So you can just check how the previous operation ended - either, for example, if (cout.good()) , or using a cast to a bool type just like if (cout) . And since I / O operations usually return a reference to a stream, even so:

 if (cout << "Hello") ... 
  • I know that they do not generate. You can simply dress them in try , but you don't want to clutter up the code. Hence the question. The answer suits me, although I hoped for error codes, not just fail / good - DNS
  • If they do not generate, then what do you want to achieve with try/catch ? It just won't work ... - Harry
  • Well, yes, I misunderstood ... - DNS