so glad to find this nice place and become part of it!
i've a trouble with implementing a function that takes a string input from the user, and returns a string vector containing each word. for instance if i write "hello asd 132134", i want the first index to be "hello", second "asd" and third the number.
when i tried to implement that, i've stumbled upon a segmentation error, and i'm sitting for hours not knowing how to fix it. i implemented it using 2 functions(will be using it multiple times in my code, so no other option).
the code worked without this error before i introduced those 2 functions. i'll supply a link to online gdb with my full code (both of the mentioned functions are in functionality.cpp): https://onlinegdb.com/SkL-SosoX (the error begins whenever i use args, for instance when i want to insert input to the tree by pressing 1)
@jonin: could you please look at the program link i gave( https://onlinegdb.com/SkL-SosoX) ? i am stuck on it for days and long hours today and i don't know what i'm missing :( would really appreciate help me with
Ah, the classical problem of mixing >> and getline. The problem is that >> leaves the newline character in the stream so if you use getline right after it will find a newline character right away and not wait for more input so it just gives you an empty string. The simplest solution to this problem in my opinion is to use std::ws before each time you use std::getline.
std::getline(std::cin >> std::ws, line);
while (std::getline(tokenStream >> std::ws, token, ' '))
You also need to fix your error checking code. The check functions just print error messages but the code continues as normal and doesn't prevent the code that expects the input to be correct from running. You need to somehow abort the action if you detect an error. If you are familiar with "exceptions" that might be something you want to consider.
That is true. What I showed will not work if there is a need to accept empty lines. It will also not work if you care about leading whitespace characters at the beginning of the line.