を行うための最善の方法を提案してくださいここ
は(あなたがブーストを使用しない場合は申し訳ありませんそして、)私はboost::tokenizerを使用して思い付いた例です。
#include <iostream>
#include <boost/tokenizer.hpp>
#include <string>
#include <vector>
int main()
{
std::vector<std::string> v;
v.push_back("1|duleep|[email protected]|0");
v.push_back("2|dasun|[email protected]|0");
v.push_back("3|sampath|[email protected]|1");
v.push_back("4|Nuwan|[email protected]|0");
boost::char_separator<char> sep("|");
std::vector<boost::tokenizer<boost::char_separator<char>>> tokens;
for (auto& s : v)
{
tokens.push_back({s, sep});
}
}
あなたがstd::string array[4][4]
を使用したい場合は、単にトークンを反復処理し、あなたに割り当てますアレイ。ここで
は、ブーストなしの別の方法です:
for (auto& s : v)
{
std::stringstream ss(s);
std::string token;
while (std::getline(ss, token, '|'))
{
// Put token into your array here
}
}
あなた 'data'は'どのようなものを見てclass'ん?演算子>>() 'をオーバーロードしましたか? – Johnsyweb
文字列をトークン化したい場合は、C++の文字列を探すことができます – Raghuram
@Raghuramそれは私の問題のための最良の解決策ですか?配列へのアクセスのような単純なアクセス方法はありますか? – user881703