写文件的时候我现在的代码是这样的strTmpFile = "C:\\1.txt"
FILE* fp = _tfopen(strTmpFile,TEXT("wb"));
if (fp)
{
fwrite(XXXXXXX);
fclose(fp);
}发现以wb打开写文件,如果文件里原来有内容,不会删除原来的内容而是从头开始覆盖着写,我现在是想每次都全部重写这个文件,应该用哪个标识?
我知道可以把文件先删了重写也达到这样的效果,但我还是希望搞清楚open后面的标识怎么用

解决方案 »

  1.   

    strTmpFile = "C:\\1.txt" 
    FILE* fp = _tfopen(strTmpFile,TEXT("w")); 
    if (fp) 

    fwrite(XXXXXXX); 
    fclose(fp); 
    }看看这样行不行呀
      

  2.   

    好像不行...我的MSDN是2008的...还没找到
      

  3.   


    char* strTmpFile = "C:\\1.txt";
    FILE* fp = fopen(strTmpFile,TEXT("wb")); 
    if (fp) 

    fwrite("sampleString",1,sizeof("sampleString"),fp ); 
    fclose(fp); 

    试了一下,没有搂主说的覆盖写的问题啊。问题有些模糊。
      

  4.   

    The character string mode specifies the type of access requested for the file, as follows:"r"Opens for reading. If the file does not exist or cannot be found, the fopen call fails."w"Opens an empty file for writing. If the given file exists, its contents are destroyed."a"
    ===========================================================================
    Opens for writing at the end of the file (appending) without removing the EOF er before writing new data to the file; creates the file first if it doesn’t exist."r+"Opens for both reading and writing. (The file must exist.)"w+"Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed."a+"Opens for reading and appending; the appending operation includes the removal of the EOF er before new data is written to the file and the EOF er is restored after writing is complete; creates the file first if it doesn’t exist.
    ==================================================================覆盖掉原先的
    FILE* fp = fopen(strTmpFile,TEXT("w+")); 
      

  5.   

    从MSDN上关于_tfopen的描述来看,应该是楼主语义表述有问题。程序应该没有问题。