vc中读取一个txt文件,每次读取一段末尾为tab键的字符串,该如何实现???
解决方案 »
- 分享一道面试题,并有个疑问
- 应用程序无法正常启动0xc000007b
- VC++中插入一个Dialog并生成了类,但是在类视图里找不到这个类,虽然文件试图里有.cpp文件和.h文件,求解?
- 接上篇帖子TCP协议发送文件(继)-(送给那些一心想要传送文件的朋友(TCP协议),写的不太好,分也不太多.)
- 求助大家,顺便散分,提前祝国庆、中秋快乐!
- xtreme toolkit如何编译debug的dll?
- 请问如何判断一个字符串是有效数字?
- 关于两台机器之间的语音传送。
- 为什么VS6.0提示:不可识别的数据库格式。我晕倒!
- 在线讨论:如下的设计怎样用VC实现?
- dll中提供一个计算的函数(需要3秒),返回值前主程序‘死掉’,怎么回避处理?
- 简单的问题 请知道的同志帮个忙把
file.Open("C:\\aa.txt",CFile::modeRead);
CString str;
file.ReadHuge(str.GetBuffer(),file.GetLength());
int index = str.Find('\t');
while(index != -1)
{
CString subStr = str.Left(index);//subStr就是截取的一段字符串
str = str.Mid(index+1);
index = str.Find('t');
}
if(str.GetLength() > 0)
{
//剩余的str是最后一段字符串
}
str.ReleaseBuffer();
CFileException e; if(!file.Open(fileName, CFile::modeRead, &e ) )
{
AfxMessageBox("Can't find index.ini!");
return;
}
char buf = '\0';
CString str;
str.Empty(); file.Read(&buf, 1);
for(int i=0; i<file.GetLength(); i++)
{
if(buf != '\t')
{
CString temp;
temp = buf;
str =str + temp;
temp.Empty();
}
else
{
int j = 0;
str = str + '\t';
//此时已经得到末尾为TAB键的一个字符串
}
file.Read(&buf, 1);
}
file.Close();这个方法有点笨,而且没有考虑换行
#include <fstream>
using namespace std;ifstream ifile("temp.txt");
char linebuf[512];
while(!ifile.eof())
{
ifile.get(linebuf, sizeof(linebuf), '\t');
ifile.get(); //跳过'\t';
}
ifile.close();
FILE *stream;
stream = fopen("c:\\YDQ.txt", "r");
if (stream != NULL)
{
while (!feof(stream))
{
fscanf( stream, "%s\t", s );
AfxMessageBox(s);
}
fclose(stream);
}