Hey guys, sorry if this is a really really noob question, but i can't find any help in my textbook or online. I've searched everything I can and I just cant make sense of it, even though I feel like it's something very simple. I'm in a programming 1 class right now with only maybe 10 weeks of practice under my belt, FYI.
So, I have this extra credit and it's based on string class functions. It asks to:
1. Write a program that reads a person’s first and last name without any spaces, but with the * symbol between the 2 names.
2. In the main function, use string class functions to extract the first name from the string and store it in a second string object.
3. Then extract the last name and store it in a third string object.
4. Test your program to make sure it works correctly by displaying all three strings.
I understand how to use the functions insert, assign, etc., but I am lost as to how to know the position of the '*'. I know I can use the find function (wholeName.find('*')) to find the asterisk, but how do I know the position of it? This is what I have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include<iostream>
#include<string>
using namespace std;
int main ()
{
string wholeName;
string firstName;
string lastName;
char index;
cout << "Please enter your whole name, with a '*' symbol instead of a space: ";
cin >> wholeName;
wholeName.find(index);
firstName.assign(wholeName, 0, index);
cout << firstName;
cout << "Please press enter once or twice to continue...";
cin.ignore().get(); // hold console window open
return EXIT_SUCCESS; // successful termination
}
|
Again, I apologize if this seems really stupid, I just can't wrap my head around it. If someone would like to actually code the program, just so i can see how it's done and not to cheat, that would also work. Any help is GREATLY appreciated. Thank you.