注意项目的当前路径
想用fopen打开当前目录下的一个txt文件,却总是找不到该文件。
困惑了几天 今晚终于把它弄明白了。
原来 打开新文件/文件夹时,更改了当前目录。所以在更改路径前务必获得并保存当前路径,以便在系统其他地方可以用fopen打开“当前目录”下的文件。
posted @ 2007-06-02 22:03 李相前 阅读(141) 评论(0) 编辑
进步进步
想用fopen打开当前目录下的一个txt文件,却总是找不到该文件。
困惑了几天 今晚终于把它弄明白了。
原来 打开新文件/文件夹时,更改了当前目录。所以在更改路径前务必获得并保存当前路径,以便在系统其他地方可以用fopen打开“当前目录”下的文件。
posted @ 2007-06-02 22:03 李相前 阅读(141) 评论(0) 编辑
posted @ 2007-03-26 08:02 李相前 阅读(24349) 评论(3) 编辑
posted @ 2006-12-08 11:34 李相前 阅读(1452) 评论(0) 编辑
|
问题描述:大部分的vs.net 2005的用户在新建“win32项目-windows应用程序”的时候,新建的工程都通不过去,出现如下提示: (转载) |
posted @ 2006-12-01 16:49 李相前 阅读(9766) 评论(8) 编辑
最近在论坛里总有人问关于sizeof的问题,并且本人对这个问题也一直没有得到很好的解决,索性今天对它来个较为详细的总结,同时结合strlen进行比较,如果能对大家有点点帮助,这是我最大的欣慰了。
一、好首先看看sizeof和strlen在MSDN上的定义:
首先看一MSDN上如何对sizeof进行定义的:
sizeof Operator sizeof expression The sizeof keyword gives the amount of storage, in bytes, associated with a variable or a type (including aggregate types). This keyword returns a value of type size_t. The expression is either an identifier or a type-cast expression (a type specifier enclosed in parentheses). When applied to a structure type or variable, sizeof returns the actual size, which may include padding bytes inserted for alignment. When applied to a statically dimensioned array, sizeof returns the size of the entire array. The sizeof operator cannot return the size of dynamically allocated arrays or external arrays.
然后再看一下对strlen是如何定义的:
strlen Get the length of a string. Routine Required Header: strlen <string.h> size_t strlen( const char *string ); Parameter string:Null-terminated string Libraries All versions of the C run-time libraries. Return Value Each of these functions returns the number of characters in string, excluding the terminal NULL. No return value is reserved to indicate an error. Remarks Each of these functions returns the number of characters in string, not including the terminating null character. wcslen is a wide-character version of strlen; the argument of wcslen is a wide-character string. wcslen and strlen behave identically otherwise.二、由几个例子说开去。
char* ss = "0123456789"; sizeof(ss) 结果 4 ===》ss是指向字符串常量的字符指针 sizeof(*ss) 结果 1 ===》*ss是第一个字符 char ss[] = "0123456789"; sizeof(ss) 结果 11 ===》ss是数组,计算到\0位置,因此是10+1 sizeof(*ss) 结果 1 ===》*ss是第一个字符 char ss[100] = "0123456789"; sizeof(ss) 结果是100 ===》ss表示在内存中的大小 100×1 strlen(ss) 结果是10 ===》strlen是个函数内部实现是用一个循环计算到\0为止之前 int ss[100] = "0123456789"; sizeof(ss) 结果 400 ===》ss表示再内存中的大小 100×4 strlen(ss) 错误 ===》strlen的参数只能是char* 且必须是以''\0''结尾的 char q[]="abc"; char p[]="a\n"; sizeof(q),sizeof(p),strlen(q),strlen(p); 结果是 4 3 3 2第二个例子:
class X
{
int i;
int j;
char k;
};
X x;
cout<<sizeof(X)<<endl; 结果 12 ===》内存补齐
cout<<sizeof(x)<<endl; 结果 12 同上
第三个例子:
char szPath[MAX_PATH]如果在函数内这样定义,那么sizeof(szPath)将会是MAX_PATH,但是将szPath作为虚参声明时(void fun(char szPath[MAX_PATH])),sizeof(szPath)却会是4(指针大小)
short f();
printf("%d\n", sizeof(f()));
输出的结果是sizeof(short),即2。
char str[20]="0123456789";
int a=strlen(str); //a=10;
int b=sizeof(str); //而b=20;
fun(char [8])
fun(char [])
都等价于 fun(char *) 在C++里传递数组永远都是传递指向数组首元素的指针,编译器不知道数组的大小如果想在函数内知道数组的大小, 需要这样做:进入函数后用memcpy拷贝出来,长度由另一个形参传进去
fun(unsiged char *p1, int len)
{
unsigned char* buf = new unsigned char[len+1]
memcpy(buf, p1, len);
}
有关内容见: C++ PRIMER?
void *malloc(size_t size),
size_t fread(void * ptr,size_t size,size_t nmemb,FILE * stream)。
void * memset(void * s,int c,sizeof(s))
(转贴 作者:房秉毅)
posted @ 2006-12-01 16:36 李相前 阅读(226) 评论(0) 编辑
| 1. | 使用自定义安装,在“Visual Studio 6.0 Enterprise – 自定义”页上,单击“企业版工具”,然后单击“更改选项”。 |
| 2. | 在“Visual Studio 6.0 Enterprise – 企业版工具”页上的“选项”下,确保未选中“Visual Studio Analyzer”复选框。 |
| 3. | 单击以选择要安装的所有其他 Visual Studio 组件,然后单击“确定”。 |
| 4. | 单击“继续”,然后按照出现的说明进行操作。 |
| 1. | 在“控制面板”中,双击“添加/删除程序”,然后单击“Microsoft Visual Studio 6.0 Enterprise Edition”。 |
| 2. | 单击“更改/删除”。 |
| 3. | 在 Visual Studio 6.0 Enterprise 安装程序中,单击“添加/删除”。 |
| 4. | 在“Visual Studio 6.0 Enterprise – 维护”页上,单击“企业版工具”,然后单击“更改选项”。 |
| 5. | 在“Visual Studio 6.0 Enterprise – 企业版工具”页上的“选项”下,单击“Visual Studio Analyzer”,然后单击“确定”。 |
| 6. | 在“Visual Studio 6.0 Enterprise – 维护”页上,单击“继续”,然后按照出现的说明进行操作。 当您收到“症状”部分中描述的错误消息时,请继续执行“Visual Studio 安装向导”。安装程序将报告失败。 |
| 1. | 在运行 Visual Studio Enterprise Edition 6.0 的计算机上,创建一个本地用户。有关如何创建本地用户的信息,请参阅 Windows 2000 帮助。 |
| 2. | 运行分布式 COM 配置 (dcomcnfg.exe)。 |
| 3. | 在“应用程序”选项卡上,单击“MSVSA 本地事件集中器类”,然后单击“属性”。 |
| 4. | 在“标识”选项卡上,将“此用户”设置为与在此过程的步骤 1 中创建的用户和密码匹配。 |
posted @ 2006-11-15 09:32 李相前 阅读(4776) 评论(2) 编辑
posted @ 2006-06-14 08:07 李相前 阅读(77) 评论(0) 编辑
posted @ 2006-06-14 08:05 李相前 阅读(941) 评论(2) 编辑
posted @ 2006-06-08 08:44 李相前 阅读(642) 评论(1) 编辑