MFC中怎么把系统输出的写入到文本中?

请问怎么在MFC框架中创建一个一个txt文本,并且把原来打算cout的东西写入到里面呢,具体对于缓冲流的过程还不是很清楚,所以希望dalao能不能详细一下具体的实现

#include
#include
using namespace std;

 void CQ692407Dlg::OnBnClickedButton1()
{
    // TODO: Add your control notification handler code here
        ostringstream cout1;
    cout1 << "a=" << 123 << ".";
    string str = cout1.str();
    m_edit1 = (CString)str.c_str();
    UpdateData (FALSE);
    ofstream cout("c:\\1.txt");
    cout << "a=" << 123 << ".";
    cout.close();
}

1.c方法:
FILE* fp;
fp=fopen();
GetDlgItemText();//获取编辑框数据
fprintf();//将编辑框数据写入到fp文件指针内
fclose();

2.C++,fstream类的操作,不细说。

3.MFC的CFile操作:
CFile file;
CString strValue;
GetDlgItemText(IDC_EDIT,strValue);//获取编辑框数据
file.WriteString(strValue);
file.Close();

使用输出流重定向 fprintf(""1,txt",std::out)

int类型变量,直接写入文件,是16进制格式,占4个byte(char)大小。

要想将int写入文本文件并直观可见,需要先转换为字符串,再写入文件

先把你的数组内容转成字CSring 类型然后拼接起来
存放在一个cstring msg中,再把msg写入到文件中就可以了:
//在指定位置创建一个文件
CStdioFile m_file("D:\sendtoclient.txt",CFile::modeCreate|CFile::modeWrite);
//清空文件内容
m_file.SetLength(0);
//将结点表内容写入指定文件
m_file.WriteString(msg);
//关闭文件
m_file.Close();

图片说明

如果问题解决,麻烦帮我采纳下,谢谢

 #include <sstream>
#include <fstream>
using namespace std;