c++高手看下。

来源:百度知道 编辑:UC知道 时间:2024/06/24 14:52:16
#include<iostream.h>
#include<afx.h>
void main()
{
char *str = (char *)malloc(100);
strcpy(str, "hello");
free(str);
if(str != NULL){
strcpy(str, "world");
cout<<str<<endl;
}
}

连接时为什么报如下错误:
Linking...
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/ddd.exe : fatal error LNK1120: 2 unresolved externals
执行 link.exe 时出错.

VC++6.0:

打开工程后,点击“工程”-“设置”,在打开的对话框中切换到“General"选项卡,将其中的“Microsoft Foundation Classes"设置为"Use MFC in a Shared DLL",确定即可。

或者
改成如下
#include<iostream.h>
#include<stdlib.h>
#include<string>
//#include<afx.h>
void main()
{
char *str = (char *)malloc(100);
strcpy(str, "hello");
free(str);
if(str != NULL){
strcpy(str, "world");
cout<<str<<endl;
}
}

把afx.h去了
换别的库文件

程序本来就有错误,将str释放掉以后并没有将str置为NULL, 所以是野指针。

连接报错是因为使用了AFX.h头文件,需要使用多线程调试。
工程(Project)-》设置(Setting)
在对话框中切换到“C/C++”标签,Category下拉框选中“Code Generation”
在下面的Use run-time librory下拉框中选中“Debug Multithreaded”或“Debug Multithreaded Dll”
然后就可以了。

#include<iostream.h>
#include <malloc.h>
#include <string.h>
void main()
{
char *str = (char *)malloc(100);
strcpy(s