dimanche 19 septembre 2021

how can i change the string permanently through for loop c++ [duplicate]

so i want an input: test and an output:t-e-s-t

but when i write this code Basically i write some function to modify the string word permanently but i dont know how to do it

void words(string word)
{
    for (auto i : word)
    {
        cout<<i<<'-'; // t-e-s-t-  #so i want these to permanently replace the string word in main:
    }
    cout<<endl;
}

//Main
int main()
{         
    string word;
    cin>>word; // test
    words(word); // t-e-s-t-
    cout<<word<<endl; // test  its not working i want the word to be permanent t-e-s-t-
    return 0; 
}

Aucun commentaire:

Enregistrer un commentaire