Here is an example I came up with using boost::tokenizer (if you don't want to use boost, then sorry):
#include <iostream>
#include <boost/tokenizer.hpp>
#include <string>
#include <vector>
int main()
{
std::vector<std::string> v;
v.push_back("1|duleep|dfe@gamil.com|0");
v.push_back("2|dasun|dasun@da.com|0");
v.push_back("3|sampath|lkdf@dg.lk|1");
v.push_back("4|Nuwan|Kandyjkj@lkj.com|0");
boost::char_separator<char> sep("|");
std::vector<boost::tokenizer<boost::char_separator<char>>> tokens;
for (auto& s : v)
{
tokens.push_back({s, sep});
}
}
If you want to use std::string array[4][4]
, just iterate through the tokens and assign them to your array.
Here is another way without boost:
for (auto& s : v)
{
std::stringstream ss(s);
std::string token;
while (std::getline(ss, token, '|'))
{
// Put token into your array here
}
}