output:1>------ Build started: Project: chapter5 使用序列式容器并分析字符串, Configuration: Debug Win32 ------
1> Source.cpp
1>Source.obj : error LNK2019: unresolved external symbol "class std::vector,class std::allocator >,class std::allocator,class std::allocator > > > __cdecl split(class std::basic_string,class std::allocator > &)" (?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\chapter5 使用序列式容器并分析字符串\Debug\chapter5 使用序列式容器并分析字符串.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
split.cpp:
//使用索引实现的split函数
#include
#include
#include
#include
using namespace std;
vector split(const string &s)
{
vector 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;
}
split.h:
#ifndef GUARD_split_h
#define GUARD_split_h
#include
#include
std::vectorstd::string split(std::string &s);
#endif
Source.cpp
#include "split.h"
#include
#include
#include
#include
using namespace std;
int main()
{
string s;
while (getline(cin, s))
{
vector<string> v = split(s);
for (vector<string>::size_type i = 0; i != v.size(); ++i)
cout << v[i] << endl;
}
return 0;
}
我用的是空项目建立的,搞不懂是为什么出问题了,新手啊