0

我编写了一个将字符串转换为向量的函数。现在我想制作一个类型的模板,因为我还想使用 wstrings 和 wchar_t。因为它们在 csv 文件中。这是我的文件...

主文件

#include <iostream>
#include <fstream>
#include "trans.h"
#include "vector_to_string.cpp"

using namespace std;

int main() {
    wifstream tstream("translation.csv");
    wstring s;

    while (getline(tstream, s)){
        vector<wstring> vec = vector_from_string(s, ',');
        wstring ws = vec[0];
        Trans<wstring> t(ws);
        wcout << t.translate(Spanish) << endl;

    }
}

vector_to_string.cpp

template <class T, typename U>
std::vector<T> vector_from_string(T to_vec, U delimit) {
    int pos = 0, len = 0;
    std::vector<T> vec;
    for (int i = 0; i < to_vec.length(); i++) {
        U c = to_vec.at(i);
        if (c == delimit) {
            vec.push_back(to_vec.substr(pos, len));
            len = 0;
            pos = i + 1;
        } else if (i == to_vec.length() - 1) {
            int end = to_vec.length() - pos;
            vec.push_back(to_vec.substr(pos, end));
        } else {
            len++;
        }
    }
    return vec;
}

翻译.csv

# English , French, German, Spanish
a,une,ein,UNE
aa,aa,aa,Automóvil club británico
aaa,aaa,aaa,aaa
aaron,aaron,aaron,Aaron
ab,un B,ab,Un B
abandoned,abandonné,verlassen,abandonné
abc,abc,ABC,a B C
aberdeen,aberdeen,aberdeen,Aberdeen
abilities,capacités,Fähigkeiten,capacités
ability,aptitude,Fähigkeit,aptitud
able,capable,imstande,capaz
aboriginal,Aborigène,Ureinwohner,aborigène
abortion,Avortement,Abtreibung,avortement
about,à propos,Über,Al respecto
above,au dessus de,über,au dessus de
abraham,abraham,abraham,Abrahán
abroad,à l'étranger,im Ausland,en el Extranjero
abs,abdos,Abs,abdos
...

问题出在 vector_to_string () 但我找不到问题,我得到这个语法错误......

undefined reference to `std::vector<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, std::allocator<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > > demonic::vector_from_string<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, wchar_t>(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, wchar_t)'

问题是什么,我怎样才能最好地解决它?

4

0 回答 0