Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

files 1

Status
Not open for further replies.

jimjake

Technical User
Oct 30, 2004
25
US
#include <iostream>
#include <fstream>
int main()
{
std::cout << "Opening output file..." << std::endl;
std::eek:fstream ofile("bobinsurance.txt");
if (!ofile.fail()) {
std::cout << "Writing to file...";
ofile << "password " << std::endl;
}
else
std::cout << "cannot open";
return 0;
}
This code works fine, and it goes into the dir. Of my complier.
If I code std::eek:fstream ofile("c:\My Doucments\text.txt”};
The complier comes back with invalid escape.
I want to write a file to My Documents……..
 
You need to use a double slash in the file name:

std::eek:fstream ofile("c:\\My Doucments\\text.txt”);

Also, you have a } instead of a ) to close the function call, that's a problem.
 
If double backslashes are annoying, I believe you can use regular slashes instead, even on Windows.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top