2011-03-21 81 views
1

我有一個文件處理問題。我正在寫的文件處理代碼,看起來像這樣:文件處理編譯錯誤

ofstream SaveFile("/home/core-site2.xml") 

//SaveFile<<"<?xml version="1.0"?>" ; 
SaveFile <<endl ; 
SaveFile<<"<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>" ; 

當我編譯這個文件我得到以下錯誤:

error: expected ‘;’ before ‘text’

什麼shouuld我做刪除錯誤? 如何正確寫入這些行?

+0

檢查您是否錯過了將分號(;)放在前一行或不放。並回複評論。你能否更正確地格式化問題? – 2011-03-21 09:26:39

回答

2

SAVEFILE的聲明錯過一個尾隨 ';'。此外,你需要逃避字符串中的引號:

SaveFile<<"<?xml-stylesheet type=\"text/xsl\" href=\"configuration.xsl\"?>" ; 
+0

這解決了我的問題 – user513164 2011-03-24 08:48:56

1
ofstream SaveFile("/home/core-site2.xml") 

此行缺少分號。

1

你在你的ofstream聲明結尾缺少一個分號。

2
ofstream SaveFile("/home/core-site2.xml"); 

SaveFile<<"<?xml-stylesheet type=\"text/xsl\" href=\"configuration.xsl\"?>" ; 
+0

thanx爲您解答我的問題的答案 – user513164 2011-03-22 05:17:01

1

SaveFile<<"<?xml-stylesheet type=\"text/xsl\" href=\"configuration.xsl\"?>" ;

你需要逃避字符串中的引號。否則,編譯器認爲它們是字符串的結尾。