Question

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?

Was it helpful?

Solution

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";

OTHER TIPS

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"; 
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top