读取文件后处理,然后保存,如何就没有反映呢
读取文件后处理,然后保存,怎么就没有反映呢?
有一个文件,A,里面的内容都是这样的:
我只想让其留下单词,每行一个,即:
这是代码:
可是我将单词本文件和单词文件都放在c盘下,运行后怎么没有反映呢?
------解决方案--------------------
我试了,读写文件本身没有错!应该是你创建窗体的问题!你可以在对话框工程中先试试
------解决方案--------------------
wchar_t ch=L'0';
if(!(ch >= L'0' && ch <= L'9'))
有一个文件,A,里面的内容都是这样的:
我只想让其留下单词,每行一个,即:
这是代码:
// youdaoword.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "youdaoword.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 唯一的应用程序对象
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
void readfile();
HMODULE hModule = ::GetModuleHandle(NULL);
if (hModule != NULL)
{
// 初始化 MFC 并在失败时显示错误
if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
{
// TODO: 更改错误代码以符合您的需要
_tprintf(_T("错误: MFC 初始化失败\n"));
nRetCode = 1;
}
else
{
// TODO: 在此处为应用程序的行为编写代码。
readfile();
}
}
else
{
// TODO: 更改错误代码以符合您的需要
_tprintf(_T("错误: GetModuleHandle 失败\n"));
nRetCode = 1;
}
return nRetCode;
}
BOOL processString(CString& str)
{
TCHAR ch=str.GetAt(0);
if(!(ch>=48&&ch<=57)) //如果不是以数字开头,就忽略
{
return false;
}
else
{
UINT iBegin = str.Find(L' ');
UINT iEnd = str.ReverseFind(L' ');
str=str.Mid(iBegin,iEnd-iBegin);
return true;
}
}
void readfile()
{
CString fileName,fileWrite;
fileName=L"c:\\wordyoudao.txt";
fileWrite=L"c:\\word.txt";
CStdioFile file(fileName,CFile::modeRead);
CStdioFile fileWord(fileWrite,CFile::modeWrite);
CString str;
//ULONGLONG dwLength=file.GetLength();
/*
while(dwLength>0)
{
UINT readLength=file.Read(buff,20);
UINT iLength=processBuff(buff,20);
fileWord.Write(buff,iLength);
dwLength-=readLength;
}
*/
while(file.ReadString(str))
{
if(processString(str))
{
fileWord.WriteString(str);
}
}
}
可是我将单词本文件和单词文件都放在c盘下,运行后怎么没有反映呢?
c
file
------解决方案--------------------
我试了,读写文件本身没有错!应该是你创建窗体的问题!你可以在对话框工程中先试试
------解决方案--------------------
wchar_t ch=L'0';
if(!(ch >= L'0' && ch <= L'9'))