mardi 22 octobre 2019

how to use iterator?

I am trying to change the characters in the string using iterator. It changes the characters before white space but it is removing the characters after that white space.

Whats happening wrong?

#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    cout<<"Enter a string : ";
    cin>>s;

    for (auto it = s.begin(); it != s.end() && !isspace(*it);++it)
      *it = toupper(*it);

    cout<<s; // capitalize the current character
    return 0;
}

Output:

Enter a string : abc abc
ABC

Aucun commentaire:

Enregistrer un commentaire