Greetings cplusplus users!
This is my first question on this site, and please, forgive me if my english is not perfect!!
Actually i'm having some trouble with an exercise i've got from my teacher.
In the exercise i have a couple of strings on a txt file:
"Hello, my name is, Nathan;
It's, a pleasure, to meet you;"
I have to extraxt the 'Nathan' and the 'to meet you' and write them in another txt but it's way too hard for me.
I know how to read the first string, but i don't know what i have to do for select the 'Nathan' and the 'to meet you'.
Would you please suggest me what function do i have to use??
Thank you guys for the answers ^^
@keskiverto I was thinking on something like "put every part of the string on an array, then i can print the array[3] because is the unique constant we have over here".
I don't know if you can help me with this "rule" .
@CodeWriter Yeah this seems a quite good function to test!
@SamuelAdams sorry but I don't think this is the best way to face the problem, the teacher might give me a txt more "long" to examinate.
By the way, thank you I really appreciate your help ^^
EDIT1: Do you think there's a way to delete every character before the 2nd ','??
Essentially keskiverto has given you the rule I didn't notice it myself.
The segments you need to "copy out" are between a comma/space and a semicolon.
The example given happens to have two such strings.
Scan until you find a comma followed by a space, then keep scanning and saving the characters in another string until you either find another comma at which point you clear the saved characters or you find a semi colon at which point the string with the saved characters is the extracted string which you can then add to a list of extracted strings.
You have to figure out how to extract a sub string from a given string where the sub string is defined as starting with a comma/space and ending with a semicolon. If a comma is found before the semicolon the string has to be discarded.
Again, the description of the syntax is what the code must be based on.
The wild guess is that you have comma separated values. The std::getline() can be told to read up to a separator (which by default is newline). If comma is the separator ...
A fixed-sized array is useful only if you have fixed number of values. If the number can differ depending on the input file, then one is better off with std::vector than array.