ifstream file path


need some help,

I am using the code below to read a file, but I can not enter the file path, I always have to move to the folder where I'm running the script

Ever tried to enter the path of the file in many ways, but does not compile

std::ifstream file("temp.txt");
Did you try with \\ ?

std::ifstream file("C:\\Temp\\temp.txt");

Unless you're targeting something really ancient like Windows 98, always use forward slashes. All modern operating systems including Windows support forward slashes in paths. Only Windows support backlashes, so using backslashes reduces the portability of your code.

@OP: Try opening an output file stream and seeing where it creates the file at - that is where the input file needs to be too.
Last edited on
thanks for help! I use \\
Topic archived. No new replies allowed.