I've been searching for quite some time and I can't find any way that's enough simple for me to understand.
Let's say I have string Text1 = "qwer.tzui" and string Text2. How would I put everything up to period (".") into string Text2, so that Text2 = "qwer".
I tried this:
1 2 3
for (int i=0; (i<Text1Size) || (Text1[i]!='.'); i++) {
Text2[i]=Text1[i];
}
But string isn't an array, so it doesn't work. I know there is a string function called find, but that only gives me a number where period is and I don't know how to use it since string isn't an array...
You have several way.
A string is an array, you need to give it an initial size in order to make the code above work.
Or you can use string operator +=
Or you can use stringstreams
Or you can use string members find and substr
see this for reference: http://www.cplusplus.com/reference/
#include <string>
#include <sstream>
//... stuff
std::string text = "qwer.tzui";
std::string text1;
std::string text2;
std::istringstream iss(text); // convert string into input stream
std::getline(iss, text1, '.'); // read up to '.' into text1 (extracting the '.')
std::getline(iss, text2); // read the rest of the string
I'm sorry, I already looked at those and its all too confusing to me, I'm a bit ahead of my knowledge... I can't get source string array to work, because I get the string from another function through pointers. I'll paste only necessary part of the code, because there's a lot of it: