在vc下怎样把通过对话框的文本框输入的文字保存为.txt文本格式?请指点。能给代码更好,能给相关文档的URL地址页感激不禁

解决方案 »

  1.   

    CStdioFile file;
    CString filename="C:\\NUM.txt";
    CString str;//假设str里保存的就是文本内容
    if(!file.Open(filename,CFile::modeCreate|CFile::modeWrite))
    {
        file.Close();
        return;    
    }
    file.WriteString(str);
    file.Close();
      

  2.   

    读出对话框中的文字,使用CFile等文件操作的类就行了。
    或者直接使用FILE也可以呀。
      

  3.   

    FILE, CFile, CSTDFile……
      

  4.   

    if(!UpdateData(TRUE)) return; //update variables related with the controls
    //select or input a file to save 
    CFileDialog savefileDlg(FALSE,"","",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
    "Phone number file(*.txt)|*.txt|");
    char path[_MAX_DIR];
    _getcwd(path, _MAX_DIR);
    savefileDlg.m_ofn.lpstrInitialDir = path;
    if(savefileDlg.DoModal()!=IDOK){
    return;
    }
    CString filename = savefileDlg.GetFileName();
    CStdioFile txtfile;
    if( !txtfile.Open( filename, CFile::modeCreate
    | CFile::modeWrite | CFile::typeText ) ) {
    #ifdef _DEBUG
    afxDump << "Unable to open file" << "\n";
    #endif
    exit( 1 );
    }//file save 
    int i;
    CString strTemp;

    strTemp.Format("%s",m_edit);
    txtfile.WriteString(strTemp);
    txtfile.WriteString("\n");
    txtfile.Close();
      

  5.   

    http://dev.csdn.net/develop/article/7/7919.shtm