Как решить данную ошибку c++ - Вопросы по С+
  • Чаты 4chT.com в телеграмм
    Наши группы в телеграмм

Вопрос Как решить данную ошибку c++

Регистрация
4 Дек 2013
Сообщения
91
Репутация
0
Спасибо
0
Монет
0
void split(char* lst[], string str, string separator = " ") {

stringstream strr(str);

char* word;

int i = 0;

int size = sizeof(lst);

while (strr >> word) {

if (i > size) { break; }

cout
 
Регистрация
24 Ноя 2013
Сообщения
86
Репутация
0
Спасибо
0
Монет
0
char* word; - объявлен указатель, память не выделена
...
while (strr >> word) - считываем что-то в никуда

если ты уже используешь std::string, забудь ты про char*, используй тот же std::string
 
Регистрация
24 Сен 2013
Сообщения
88
Репутация
0
Спасибо
0
Монет
0
#include
#include
#include
#include
#include

using namespace std;

vector split(const string& line) {
stringstream ss(line);
list lst;
string word;
while (ss >> word) lst.push_back(word);
vector words(lst.size());
copy(lst.begin(), lst.end(), words.begin());
return words;
}

string input_string(const char* prompt) {
cout
 
Регистрация
27 Окт 2013
Сообщения
89
Репутация
-3
Спасибо
0
Монет
0
#include
#include
#include
#include

void split(std::vector& lst, const std::string& str, const std::string& separator = " ") {
std::stringstream strr(str);
std::string word;

while (std::getline(strr, word, separator[0])) {
lst.push_back(word);
}
}

int main() {
std::vector words;
std::string text = "This is a test string";
std::string sep = " ";

split(words, text, sep);

for (const auto& word : words) {
std::cout
 
Регистрация
30 Сен 2013
Сообщения
81
Репутация
0
Спасибо
0
Монет
0
В предоставленном куске я вижу ошибку
int size = sizeof(lst);
Которая не "посчитает" размера массива
 
Сверху Снизу