i want to read a file which consists of 1's and 0's in each line, how do can i store a false in any bool variable after reading 0 from the file.
language c++
i want to read a file which consists of 1's and 0's in each line, how do can i store a false in any bool variable after reading 0 from the file.
language c++
Just read into a boolean variable:
bool b;
file >> b;
where file is your input file stream. 1's will be converted to true, 0's to false.
If you have read into a string, the obvious way to do the conversion is to look at the first character:
string s = .... // populate
bool b = s[0] != '0';
but I can't see why you would read into a string if what you really want is a bool.