2010-11-18 49 views
1

我想寫出文件中的引號,但我不知道語法應該如何顯示。使用ofstream將文章引用到文本文件中使用C++編寫

ofstream file("myfile.txt"); 
    if (file.is_open()) 
    { 
     file << "\n"; 
     file << ""type of file""<< "=" << '\n'; // obviously this is wrong 
     file << "name = \n"; 
    } 

我想要的文本文件看起來像這樣:

「文件類型」=

名=

我怎麼能這樣做?

回答

2

使用\",而不是僅僅",即:

file << "\n"; // note not "/n" 
file << "\"type of file\"" << "=" << "\n"; 
file << "name = \n"; 

當然中間線可能只是:

file << "\"type of file\"=\n"; 
1

使用轉義字符

file << "\"type of file\"" << "=" << "\n"; 
3

您應該能夠逃脫"\所以\"

file << "\"type of file\""<< "=" << '\n'; 
0
if (ofstream file("myfile.txt")) 
{ 
    file << "/n" 
      "\"type of file\"=\n" 
      "name = \n"; 
}