在我的一个项目中,此代码编译没有问题。
但是在另一个项目使用相同的文件,它不会编译。我正在使用VS2012,并且两个项目之间的C / C ++属性是相同的。我在这里搜索但找不到任何东西。任何帮助表示赞赏!
标题文件:
#include <vector>
extern void split(const wstring &s, WCHAR c, vector<wstring>& v);
C ++文件:
void split(const wstring& s, WCHAR c, vector<wstring>& v)
{
string::size_type i = 0;
string::size_type j = s.find(c);
while (j != string::npos) {
v.push_back(s.substr(i, j-i));
i = ++j;
j = s.find(c, j);
if (j == string::npos)
v.push_back(s.substr(i, s.length()));
}
}
这就是我调用函数的方式:
wstring csToken;
vector<wstring> vProductVersion;
TCHAR *sProductVersion = tcalloc(64);
StringCchCopy(sProductVersion,64,L"3.3.422");
// Put the string into a vector array.
csToken.assign(sProductVersion);
split(csToken, '.', vProductVersion);
以下是编译器生成的错误:
1>c:\\projects\\functions.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\\projects\\functions.h(5): error C2143: syntax error : missing ',' before '&'
答案 0 :(得分:3)
您需要在标题
中的wstring前添加名称空间#pragma once
#include <string>
#include <vector>
extern void split(const std::wstring &s, WCHAR c, std::vector<std::wstring>& v);
添加防护装置也很好,因此在包含时不会多次包含防护装置。 (#pragma once
)