c++中依次读取文件中的数据并且进行运算

yexin11 2014-11-07 10:07:16

使用c++怎么能够有顺序的读取文本中的数据啊?并且进行相应的运算
...全文
425 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaohuh421 2014-11-07
  • 打赏
  • 举报
回复
fopen 打开文件 fgets 一次读取一行 strtoks 拆分字符串 fclose 关闭文件
fztfztfzt 2014-11-07
  • 打赏
  • 举报
回复
yexin11 2014-11-07
  • 打赏
  • 举报
回复
引用 楼主 u012742793 的回复:
使用c++怎么能够有顺序的读取文本中的数据啊?并且进行相应的运算
你这个能不能写的具体点啊,给个简单的事例
yexin11 2014-11-07
  • 打赏
  • 举报
回复
引用 2 楼 fztfztfzt 的回复:
一次读取本文件夹下的dll文件:
bool GetPluginNames(vector<string> &v)
{
	WIN32_FIND_DATA FindFileData;
	HANDLE hfind = INVALID_HANDLE_VALUE;
	string strDirSpec;// = PLUGIN_PATH;
	strDirSpec +="*";
	hfind = FindFirstFile(strDirSpec.c_str(),&FindFileData);
	if(hfind == INVALID_HANDLE_VALUE)
	{
		return false;
	}
	do {
		int length = strlen(FindFileData.cFileName);
		if((FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) || length<4 )
		{
			continue;
		}
		if(!((FindFileData.cFileName[length-1] == 'l') || (FindFileData.cFileName[length-1] == 'L')))
		{
			continue;
		}
		if(!((FindFileData.cFileName[length-2] == 'l') || (FindFileData.cFileName[length-2] == 'L')))
		{
			continue;
		}
		if(!((FindFileData.cFileName[length-3] == 'd') || (FindFileData.cFileName[length-3] == 'D')))
		{
			continue;
		}
		if(FindFileData.cFileName[length-4] != '.') continue;
		string strName ;//= PLUGIN_PATH;
	//	strName +="\\";
		strName += FindFileData.cFileName;
		v.push_back(strName);
	} while(FindNextFile(hfind,&FindFileData));
}
你这个是dll那后面的怎么写啊,请写具体点,跪谢
yexin11 2014-11-07
  • 打赏
  • 举报
回复
回复于: 2014-11-07 12:45:12 fopen 打开文件 fgets 一次读取一行 strtoks 拆分字符串 fclose 关闭文件 你好,能具体说一下么?写个完整的具体事例
fztfztfzt 2014-11-07
  • 打赏
  • 举报
回复
一次读取本文件夹下的dll文件:
bool GetPluginNames(vector<string> &v)
{
	WIN32_FIND_DATA FindFileData;
	HANDLE hfind = INVALID_HANDLE_VALUE;
	string strDirSpec;// = PLUGIN_PATH;
	strDirSpec +="*";
	hfind = FindFirstFile(strDirSpec.c_str(),&FindFileData);
	if(hfind == INVALID_HANDLE_VALUE)
	{
		return false;
	}
	do {
		int length = strlen(FindFileData.cFileName);
		if((FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) || length<4 )
		{
			continue;
		}
		if(!((FindFileData.cFileName[length-1] == 'l') || (FindFileData.cFileName[length-1] == 'L')))
		{
			continue;
		}
		if(!((FindFileData.cFileName[length-2] == 'l') || (FindFileData.cFileName[length-2] == 'L')))
		{
			continue;
		}
		if(!((FindFileData.cFileName[length-3] == 'd') || (FindFileData.cFileName[length-3] == 'D')))
		{
			continue;
		}
		if(FindFileData.cFileName[length-4] != '.') continue;
		string strName ;//= PLUGIN_PATH;
	//	strName +="\\";
		strName += FindFileData.cFileName;
		v.push_back(strName);
	} while(FindNextFile(hfind,&FindFileData));
}

64,325

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧