2016-05-30 40 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应该罚款两种情况,如果你不希望在它的存在是为了截断它。