open a file from a folder with ifstream

I want to cout a file called "colist"(Not a .txt), but it's not on the main folder, I'm not getting any issue when I load the file on the same folder than the main.exe but I can't load it when I try to load it from the "bin" folder and I don't get why.
Here's the code:

1
2
3
4
5
6
7
8
9
else if(commands == "help") {
            ifstream helpfile ("bin\colist");
            if (helpfile.is_open()) {
                while ( getline (helpfile,line) ) {
                    cout<<line<<'\n';
                }
                helpfile.close();
            }
        }


Im on Windows 7 using code::blocks
backslash is used to escape characters, so \c in "bin\colist" will be treated as some special character. If you want to use backslash in strings you need to escape the backslash by adding an extra backslash: "bin\\colist"

You could use forward slashes instead of backslashes if you want.

 
"bin/colist"

Backslashes only work on Windows but forward slashes work everywhere .
Topic archived. No new replies allowed.