我一直在关注斯坦福在线编程抽象课程
Here is the link 作业使用各种斯坦福图书馆,如“genlib.h”,“simpio.h”......等等。
我在项目属性中包含了所有头文件 - >其他包含目录。
然而,当我编译程序时,它会抛出
错误LNK2019:函数中引用了未解析的外部符号_main ___ tmainCRTStartup
这是我在第一次热身作业中的代码
/*
* Program: warmup.cpp
* --------------------
* Program used to generate a hash code based on user's name.
* As given, this code has two compiler errors you need to track down
* and fix in order to get the program up and running.
*
* jzelenski Thu Apr 1 12:27:53 PST 2004
*/
#include <iostream>
#include <istream>
#include "genlib.h"
#include <string.h>
#define MAX_HASH_CODE 10000 // Upper bound for hash codes generated by program
/* Function prototypes */
int Hash(string s, int maxCode);
/*
* Function: Hash
* Usage: hash_number = Hash(key, max_hash);
* -----------------------------------------
* This function takes the key and uses it to derive a hash code,
* which is an integer in the range [0, maxCode - 1]. The hash
* code is computed using a method called linear congruence.
*/
#define Multiplier -1664117991L // Multiplier used in Hash function
int Hash(string s, int maxCode)
{
unsigned long hashcode = 0;
for (int i = 0; i < s.length(); i++)
hashcode = hashcode * Multiplier + s[i];
return (hashcode % maxCode);
}
int main ()
{
string name = "abc";
cout << "Please enter your name: ";
int hashcode = Hash(name, MAX_HASH_CODE);
cout << "The hash code for your name is " << hashcode << "." <<endl;
return 0;
}
我正在使用VS 2012.如果不包含.lib文件或.cpp文件,此错误是否必须执行任何操作?我记得在其他c ++库中执行此操作,并在Linker下的其他依赖项下添加.lib文件 - &gt;输入。但我无法访问任何.lib文件。只是.h和.cpp文件。
我需要修复这个问题,以便我可以继续进行其他任务。任何帮助将不胜感激。谢谢!