1

I have the code below, the program needs to read a file that contains int and string. I insert every word into a string type object and then casting it to int if I need to. when I'm trying to check whether something wrong appeared with ss.fail() or ss.bad() it returns true (I guess because I insert int into a string object). so I need a way to check if the file read ok.

while(!line_stream.eof())
{
    std::string string_value;
    line_stream >> string_value;
    if(string_value == SOME_WORD)
    {
        try
        {
          object_map[name].push_back(NA_NUM);
        }
        catch (const std::exception &e)
        {
          return FAILURE;
        }
    }
    if(string_value != "\r" && !string_value.empty())
    {
        int int_value = std::stoi(string_value);
        try
        {
           object_map[name].push_back(int_value);
        }
        catch (const std::exception &e)
        {
           return FAILURE;
        }
    }
}
Danielle
  • 25
  • 2

0 Answers0