sivan shani
sivan shani

Reputation: 87

can't initialize ifstream "Error reading characters of string"

the following gives me strange message: The message appears inside ifstream text, (when hovering it) path is a full windows style path, e.g.: "C:\t.txt"

void checkInput(string path)
{
ifstream text(path);
    // "...<Error reading characters of string.>..."
if (text.is_open())
{
    if (text.good())
               ...

the full message:

{_Filebuffer={_Set_eback=0xcccccccc <Error reading characters of string>.
_Set_egptr=0xcccccccc <Error reading characters of string>. ...} }
std::basic_ifstream<char,std::char_traits<char>> "

I tried to use char* instead string, and string.c_str. no good.

Thx for the answers, it seems the code running even though I still get this message. previously I had another error in my code.

I thought of deleting this, but it might help to know that this message doesn't prevent the code from run.

Upvotes: 1

Views: 4095

Answers (1)

user2598163
user2598163

Reputation: 11

  1. If you use path like you wrote "C:\t.txt" - it's incorrect. Use must use double backslash, like "c:\\t.txt"
  2. If you use absolute path than check file exists with such a path.
  3. If you use relative path, it depends on where you run your code: from VS (debug mode) or just run executable.

Upvotes: 1

Related Questions