Error reading result file.You should use exception handling concepts.
- Inicie sesión o regístrese para enviar comentarios
```
#include
#include
#include
#include
#include
using namespace std;
int main(){
string s;
int n;
getline(cin,s); // read a string
try{
// bitset constructor throws an invalid_argument if initialized
// with a string containing characters other than 0 and 1
//bitset<5> mybitset (string("[a-z0-9]{0,6}"));
// convert to string to int
n = stoi(s);
cout << n;
}
// if s cannot be converted to an integer, print Bad String
catch(invalid_argument& ia){
cerr << "Bad String" << ia.what() << endl;
return 1;
}
return 0;
}
```
What's my problem?
I don't understand.
You do not even show us the error! Anyway, I personally use boost::lexical_cast: https://www.boost.org/doc/libs/1_68_0/doc/html/boost_lexical_cast/examples.html#boost_lexical_cast.examples.strings_to_numbers_conversion
- Inicie sesión o regístrese para enviar comentarios