여기 (다음, 죄송 부스트를 사용하지 않는 경우) 내가 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