Write quotes to a text file using ofstream, c++
I want to write out quotes to be in the file and I don't know how the syntax should look.
ofstream file("myfile.txt");
if ( file.is_open())
{
file << "\n";
file << ""type of file""<< "=" << '\n'; // obviously this is wrong开发者_开发知识库
file << "name = \n";
}
I want the text file to look like so:
"type of file" =
name =
How can I do that?
Use \"
instead of just "
, i.e.:
file << "\n"; // note not "/n"
file << "\"type of file\"" << "=" << "\n";
file << "name = \n";
Of course the middle line could just be:
file << "\"type of file\"=\n";
You should be able to escape the "
with \
so \"
file << "\"type of file\""<< "=" << '\n';
Use the escape character
file << "\"type of file\"" << "=" << "\n";
if (ofstream file("myfile.txt"))
{
file << "/n"
"\"type of file\"=\n"
"name = \n";
}
精彩评论