This is the part of code where I try to open the file f1.txt, it is complete path is C:UsersHpDesktopNSGA2-CDSDataSetf1.txt
ifstream fichier("C:UsersHpDesktopNSGA2-CDSDataSetf1.txt", ios::in);
The file cannot be opened and I don’t know why?!
NSGA2-CDS is the folder that contain the visual studio solution
2
Answers
You have to escape backslashes in the path string:
This has nothing to do with file I/O as such; it’s a feature of string literals:
is used to escape special characters (such as
n
,t
), so when it appears in a string, it needs to be escaped as well.you can also use raw string literal so you don’t need to escape individual char.