I am currently trying to output the contents of the hosts file and eventually once I figure this part out, I will add entries and delete them later (which is why I am using fstream (I think?)) I am not extremely versed in programming and need some direction as I have never programmed for OSX before.
My program seems to not be able to navigate to the directory and returns with "Unable to open file" when I run it. How can I specify the correct directory? I am used to Windows where you can specify C:, D:, E; drives.
fstream f ("/private/etc/hosts");
if (f.is_open())
{
while (f.good())
{
getline (f,line);
cout << line << endl;
}
f.close();
} else
cout << "Unable to open file" << endl;
Backslash \\
is Windows-specific directory separator. Use proper slash /
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.