使用SDI应用程序(MFC)从文本文件读取数据并显示数据
Read a data from a text file and display data using SDI Application (MFC)?
从文件中读取和写入对我来说更容易,但我无法在SDI应用程序(MFC)中完成。。。。我需要一些指导来解决这个问题。。。。。。。。。。这是构造函数
CFileDoc::CFileDoc()
{
// TODO: add one-time construction code here
CFileDialog m_IdFile(true);
if(m_IdFile.DoModal()==IDOK)
m_sFileName= m_IdFile.GetFileName();
fstream outFile;
string data;
outFile.open(m_sFileName,ios::in);
{
while(outFile.eof()!=true)
{
getline(outFile,data);
m_sName=data;
}
}
outFile.close();
}
这一部分我做错了
m_sName=data;
因为m_sName的数据类型是CString,而数据的数据类型则是字符串
CString m_sName;
string data;
错误是
binary '=' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)
不能将std::string
分配给CString
,但CString
有一个接受const char*
:的构造函数
m_sName = data.c_str();
此外,while(outFile.eof()!=true)
是错误的(最后一次读取操作将在设置eof
之后完成!),您应该执行:
while (getline(outFile, data))
{
...
相关文章:
- C++将文本文件中的数据读取到结构数组中
- 为 Sql 服务器实现 odbc 包装器.将数据库数据读取为字符或要求驱动程序将数据转换为 C 类型
- 如何将来自文本文件的数据读取到结构的int阵列中
- 如何将不同长度的数据读取到 2D 数组中
- 从TXT文件到C 的结构向量中的数据读取
- 将sqlite原始数据读取到qbyTearray
- 如何将来自输入TXT文件的数据读取到2 C 数组中
- 使用MQQueue将数据读取到缓冲区中时麻烦
- 在 VC++ 中将类数据读取和写入二进制文件
- 将数据从数据读取器终端获取到GUI(QtCreator)
- C 将数据读取到一个结构,但它跳过了我的一个获取线,使该元素空白
- C++将二进制数据读取到结构
- c++我需要将文件中的数据读取到多维数组中,然后用一种数据类型对数组进行排序.怎样
- 对齐数据:速度取决于恒定数据读取的相对采样大小和采样频率
- 如何将文件中的数据读取到数组中
- 如何使用Visual C++应用程序的完整应用程序数据读取Minidump的应用程序数据
- 如何将csv文件数据读取到数组中
- 用C++将格式化的数值数据读取到数组中
- 正在从文件中将数据读取到结构数组中
- 将分离的数据读取到数组结构c++中