As in the topic, while I execute the following code .rdstate() returns value 2. What do I do wrong?
string logger_path_and_name("\"F:\\windowsqnx\\loggs\\logger_file.dat");
/* file to store simulation data */
std::ofstream fout( logger_path_and_name.c_str(), std::ios_base::out | std::ios_base::binary);
/* check if ios::binary supported */
if (!fout.is_open())
{
std::cerr << "can't create file logger_file.dat\n";
std::cerr << fout.rdstate();
system("PAUSE");
exit(EXIT_FAILURE);
}
Your issue is that this turns into
"F:\windowsqnx\loggs\logger_file.dat. As you can see, you have an orphan"at the beginning.You can fix this in two ways.
1. Place another
\"at the end.2. Remove the
\"at the beginningOn a side note, ios::rdstate returns a Bitmask type and the way you retrieve the information is by using
bitwise AND or ORwith the iostate flags.Example that was shamefully stolen from here: