2016-05-30 81 views
1

如果我想追加到可能存在或不存在的文件... 什麼是正確的代碼?Qt文件追加開放模式

if(!file.exists()){ 
    mode= QIODevice::WriteOnly | QIODevice::Text; 
}else{ 
    mode= QIODevice::Append | QIODevice::Text; 
} 
if(!file_destino.open(mode)){ 
    balblabla... 
} 

或者:

if(!file_destino.open(QIODevice::Append | QIODevice::Text)){ 
    balblabla... 
} 

或者:

if(!file_destino.open(QIODevice::Append | QIODevice::WriteOnly | QIODevice::Text)){ 
    balblabla... 
} 

回答

2

QIODevice::Append | QIODevice::Text應該罰款兩種情況,如果你不希望在它的存在是爲了截斷它。