C/C++ DIR遍历函数
#include <list.h>
#include <dirent.h>
#include <iostream.h>
#include <sys/stat.h>
#include <sys/types.h>
/*****************************************************************
*函数功能: 目_录_遍_历.
*返回值: 成功返回0,失败返回非0.
*参数 path : 开始遍历的路径(最好不要使用相对路径)
* l : 保存找到路径的std:list对象
* field: 要查找的目录名称.
* 如: list("/home/wyq/",list,"tmp");
* 则可以找到 /home/wyq/*/tmp/
* 如: list("/home/wyq/",list,"tmp/template");
* 则可以找到 /home/wyq/*/tmp/template
*
*****************************************************************/
int listDir(const char *path,list<string> &l,char * field = NULL)
{
using namespace std;
string Path(path);
DIR *pDir ;
struct dirent *ent ;
char childpath[10240];
string childStr;
if ( NULL == path )
{
return -1;
}
if ( '/' != Path[Path.length()-1] )
{
Path.append(1,'/');
}
if ( '/' != Path[0] )
{
Path.insert(0,"/");
}
if ( NULL == ( pDir=opendir(Path.c_str()) ) )
{
return -1;
相关文档:
Boss说,要看OpenGL,看了快一个月,总算出了个像样的东西,用C写了个3D迷宫,
虽然只有350行
代码,不过边学边写,足足写了一周时间,还是小有成就感的,活活活!
&n ......
一、XML只有一个Table的情况
(1)userInfo.xml
<?xml version="1.0" encoding="utf-8" ?>
<UserInfo ......
在Windows 2000/XP中,"Documents and Settings"是一个特殊文件夹。用户配置文件、桌面。甚至连密钥信息都保存在这里面。如果硬盘空间不够,想把它们换个地方。但这些东西却很难移动。我们的问题是:如何在保证系统正常运行的情况下,将"Documents and Settings"文件夹移动到另外一个分区?
......
1.求下面函数的返回值(微软)
int func(x)
{
int countx = 0;
while(x)
{
countx ++;
x = x&(x-1);
}
return countx;
}
假定x = 9999。 答案:8
思路:将x转化为2进制,看含有的1的个数。
2. 什么是“引用”?申明和使用“引用”要注意哪些问题?
答:引用就是某个目标变量的&ldquo ......