Вот код для utils.hpp: < /p>
Код: Выделить всё
#include
#include
#include
< /code>
strsplit.hpp:
#include
std::vector split(const std::string& str, char delimiter) {
std::vector tokens;
size_t start = 0, end;
while ((end = str.find(delimiter, start)) != std::string::npos) {
tokens.push_back(str.substr(start, end - start));
start = end + 1;
}
tokens.push_back(str.substr(start)); // Add the last token
return tokens;
}
< /code>
и основной файл: < /p>
#include "utils.hpp"
#include "strsplit.hpp"
using namespace std;
int main () {
string input;
vector splitString;
string arg0;
char delim = ' ';
while (true) {
cout > input;
splitString = split(input, delim);
arg0 = splitString[0];
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79774776/vectors-occasionally-printing-all-items-while-trying-to-print-one-in-c[/url]
Мобильная версия