#include <iostream>
#include <vector>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/range/adaptor/transformed.hpp>
int main() {
const std::string input_string = "Hello world! String with spaces.";
std::vector<std::string> words;
boost::split(words, input_string, boost::algorithm::is_any_of(" "), boost::algorithm::token_compress_on);
std::cout << "{"
<< boost::algorithm::join(words | boost::adaptors::transformed([](auto &s){return "\"" + s + "\"";}), ", ")
<< "}"
<< std::endl;
return 0;
}
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char line[] = " abc def, ghi ";
char *arr[3];
char *p;
p = line;
for (int i = 0; i < 3; i++) {
p = strtok(p, " ,");
if (p) {
arr[i] = p;
p = NULL;
} else {
break;
}
}
for (int i = 0; i < 3; i++) {
cout << arr[i] << endl;
}
return 0;
}
[guest@localhost cpp]$ .iso++ t.cpp -o t
[guest@localhost cpp]$ ./t
abc
def
ghi
[guest@localhost cpp]$