win2000,vc6.0控制台做了小程序。共三个文件,libcpp.h(定义了一个struct结构)
libcpp.cpp(是struct结构的内部函数实现)
testlibcpp.cpp(是一个主函数)遇到一点小困难,请求帮助。
源代码和出错信息如下
我是新手,高手一看会马上知道答案的源码://libcpp.hstruct stash
{
//properties
int size;
int quantity;
int next;
unsigned char* storage;
//functions
void initialize(int Size);
void cleanup();
int add(void* element);
void * fetch(int index);
int count();
void inflate(int increase);
};//libcpp.cpp
#include "libcpp.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>void stash::initialize(int Size)
{
size = Size;
quantity = 0;
next = 0;
storage = 0;
}void stash::cleanup()
{
if (storage)
{
puts("freeing storage");
free(storage);
}
}int stash::add(void * element)
{
if (next >= quantity)
inflate(100);
memcpy(&(storage[next * size]), element, size);
next++;
return(next - 1);
}void * stash::fetch(int index)
{
if (index >= next || index < 0)
return 0;
return &(storage[size * index]);
}int stash::count()
{
return next;
}void stash::inflate(int increase)
{
void * v = realloc(storage, (quantity + increase) * size);
assert(v);
storage = (unsigned char *)v;
quantity += increase;
}//testlibcpp.cpp#include "libcpp.h"
#include <assert.h>
#include <stdio.h>
#define BUFSIZE 80int main()
{
stash intStash, stringStash;
int i;
FILE * file;
char buf[BUFSIZE];
char * cp;
intStash.initialize(sizeof(int));
for (i=0; i<100; i++)
intStash.add(&i);
stringStash.initialize(sizeof(char) * BUFSIZE);
file = fopen("testlibcpp.cpp", "r");
assert(file);
while(fgets(buf, BUFSIZE, file))
stringStash.add(buf);
fclose(file);
for (i = 0; i < intStash.count(); i++)
printf("intStash.fetch(%d) = %d\n", i, *(int *)intStash.fetch(i));
i = 0;
while((cp = (char *)stringStash.fetch(i++)) != 0)
printf("stringStash.fetch(%d) = %s", i - 1, cp);
putchar('\n');
intStash.cleanup();
stringStash.cleanup();
return 0;
}

解决方案 »

  1.   

    不好意思,错误如下:
    --------------------Configuration: structhigh - Win32 Debug--------------------
    Linking...
    LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
    Debug/structhigh.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.
    Creating browse info file...structhigh.exe - 2 error(s), 0 warning(s)
      

  2.   

    你建成Win32 Application了,你应该建一个Win32 console Application,然后添加你的文件就可以了。
      

  3.   

    或者直接
    Project->Settings
    C/C++页Project Options里有一个_WINDOWS改为_CONSOLE
    Link页Project Options里有一个windows,改为console就可以了。