lundi 4 mars 2019

splitting words for full name in only one variable

    #include <iostream>
    #include <string>
    #include <cstring>
    using namespace std;



int main()
{
     string FullName;
             int i = 0;
             cout <<"Enter your full name "<<endl;
               getline(cin,FullName);

            while (FullName[i] != ' ')
            {
                cout<<FullName.substr(i,FullName.find(' '))<<endl;;
                i++;
            }

            cout <<endl;
            }
return 0

}

**i want to separate a full name from each other it only works for first name i want to separate each name in a separate line like this
if i enter this: Max Michael Max output will be Max Michael Max each name in a separate new line how i can split names each one in separate line ?

Aucun commentaire:

Enregistrer un commentaire