0
#include <iostream>
#include <vector>
#include <string>
/*Função para fazer split*/
std::vector<std::string> split(std::string s, char c)
{
std::string buff{""};
std::vector<std::string> v;
for(auto n:s)
{
if(n != c) buff+=n;
else if(n == c && buff != "") { v.push_back(buff); buff = ""; }
}
if(buff != "") v.push_back(buff);
return v;
}
using namespace std;
int main()
{
/*Quero passar os elementos(linhas) desse vector...*/
std::vector<std::string> strOrigin;
strOrigin.push_back("Uma frase legal aqui...");
strOrigin.push_back("Uma frase mais legal ainda aqui");
/*Para esse vector, de forma que eu possa acessar os elementos assim: strCurrent[i][j], onde i eram as linhas do meu vector antigo, e j são os elementos de cada linha*/
std::vector<std::string> strCurrent;
auto IteratorOrigin = strOrigin.begin();
strCurrent.push_back(split(IteratorOrigin[0], ' '));
return 0;
}
I want a new vector to receive elements of the strings(lines) I took from another vector, so that I can access, from the new vector, like this: nameDoVector[i]/In the i element of this vector, would be the elements of the string of line i of the previous vector[j]//and that would be the elements. The error that is happening with this code is as follows:
exit status 1
main.cpp: In function 'int main()':
main.cpp:28:43: error: could not convert 'strOrigin' from 'std::vector<std::__cxx11::basic_string<char> >' to 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}'
strCurrent.push_back(split(strOrigin, ' '));
Okay, I need a go to do with more than one vector line, to do an automated one, but in this case, I can’t even do it with one line.... kkk