C++无法使用vector <string>作为返回类型

Wil*_*all 2 c++ string vector return-type

我试图使用这里建议的函数来分隔字符串,但每当我尝试vector<string>用作返回类型时,我会收到一些错误.

我做了一个简单的函数,返回一个vector<string>测试,但仍然得到相同的错误:

// Test.h
#pragma once

#include <vector>
#include <string>

    using namespace std;
using namespace System;

namespace Test
{
    vector<string> TestFunction(string one, string two);
}
Run Code Online (Sandbox Code Playgroud)

.

//Test.cpp
#include "stdafx.h"
#include "Test.h"

namespace Test
{
    vector<string> TestFunction(string one, string two) {
        vector<string> thing(one, two);
        return thing;
    }
}
Run Code Online (Sandbox Code Playgroud)

以及错误的屏幕截图: 错误

有谁知道为什么我似乎无法vector<string>用作返回类型?

hmj*_*mjd 14

这不是一个有效的vector<string>构造函数:

vector<string> thing(one, two);
Run Code Online (Sandbox Code Playgroud)

改为(例如):

std::vector<std::string> TestFunction(std::string one, std::string two) {
    std::vector<std::string> thing;

    thing.push_back(one);
    thing.push_back(two);

    return thing;
}
Run Code Online (Sandbox Code Playgroud)

还要考虑更改参数const std::string&以避免不必要的复制.