samedi 1 juillet 2017

Why doesn't my string elements print?

This just asks "what your name is" and returns the string answer.

string askName(){
    string name, n;
    cout<< "what's your name?";
    cin>> name;
    getline(cin,n);
    return n;

}

It receives a string here, but it doesn't print every element. Can someone explain why it works with an actual string, but not with a received string?

void changeName(string name){

    string str(name);
    int x = 0;
    for (int i = 0; i < str.size(); i++){
    cout << str[i]<< endl; 
}

Aucun commentaire:

Enregistrer un commentaire