change invidual characters in string


I would like to know how to access a
string = "hello you";
with
char a;
I would like for an example take out the first l and the y, then change the character value to

char a={a+2};

so the changes also will permit in the string which the characters has been taken from.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
#include <cctype>

int main()
{
   std::string s = "hello you";

   std::cout << s << std::endl;

   for ( char &c : s ) c = std::toupper( c );

   std::cout << s << std::endl;

   for ( std::string::size_type i = 0; i < s.size(); i++ ) s[i] = std::tolower( s[i] );

   std::cout << s << std::endl;
}
 


Last edited on
Thanks for a so quick answear
I enlarged the example.
Topic archived. No new replies allowed.