c++新手求助,VS2013出现error LNK2019和LNK1120,请问如何解决?

chaichao27 2015-04-01 09:04:31
在VS2013里我选的是空项目

代码:
split.h

#ifndef GUARD_split_h
#define GUARD_split_h

#include <vector>
#include <string>
std::vector<std::string> split(std::string &s);

#endif


split.cpp:

//使用索引实现的split函数
#include <string>
#include <vector>
#include <iostream>
#include <cctype>

using namespace std;

vector<string> split(const string &s)
{
vector<string> ret;
typedef string::size_type string_size;
string_size i = 0;

while (i != s.size())
{
while (i != s.size() && isspace(s[i]))
++i;

string_size j = i;
while (j != s.size() && !isspace(s[j]))
++j;

if (i != j)
{
ret.push_back(s.substr(i, j - i));
i = j;
}
}
return ret;
}


Source.cpp:
#include "split.h"
#include <iostream>
#include <string>
#include <vector>
#include <iterator>

using namespace std;

int main()
{
string s;

while (getline(cin, s))
{
vector<string> v = split(s);

for (vector<string>::const_iterator iter = v.begin();
iter != v.end(); ++iter)
cout << *iter << endl;
}
return 0;
}
================
output:
1>------ Build started: Project: chapter 5 (4), Configuration: Debug Win32 ------
1>Source.obj : error LNK2019: unresolved external symbol "class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > __cdecl split(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?split@@YA?AV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z) referenced in function _main
1>C:\Users\cc\Desktop\Accelerated C++\exercise\chapter 5 (4)\Debug\chapter 5 (4).exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
...全文
348 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fly_dragon_fly 2015-04-02
  • 打赏
  • 举报
回复
声明改为 std::vector<std::string> split(const std::string &s);
微型蚂蚁 2015-04-01
  • 打赏
  • 举报
回复
检查一下你的函数声明和实现,不是同一个 std::vector<std::string> split(std::string &s); vector<string> split(const string &s)

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧