Some trubble whit the sting class

Hello fellows.
Im a novice programmer trying to learn c++ to help me in my work with robotics.
Its comming along quite well but i ran in to problems with the string class.

Im working on an assignment i found at a teachers rescource homepage.
What im supposed to do is read in a string then convert all the consonants to:'cons'+'o'+cons:

So Hello becomes: Hohelollolo

I can do this with the use of arrays but it says use strings:
This is waht i got so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<iostream>
#include<string>

using namespace std;

int main()
{

	string text;
	string konverterad="abc";
	int i=0,n=0,j=0;

	cout<<"Please type what to convert:";
	cin.get(text,299);
	cout<<"\n";
	j=text.size();
	while(i<=j){
		if (text[i] == 'b' || text[i] == 'B' || text[i] == 'c' || text[i] == 'C' ||
			text[i] == 'd' || text[i] == 'D' || text[i] == 'f' || text[i] == 'F' ||
			text[i] == 'g' || text[i] == 'G' || text[i] == 'h' || text[i] == 'H' ||
			text[i] == 'j' || text[i] == 'J' || text[i] == 'k' || text[i] == 'K' ||
			text[i] == 'l' || text[i] == 'L' || text[i] == 'm' || text[i] == 'M' ||
			text[i] == 'p' || text[i] == 'P' || text[i] == 'q' || text[i] == 'Q' ||
			text[i] == 'r' || text[i] == 'R' || text[i] == 's' || text[i] == 'S' ||
			text[i] == 't' || text[i] == 'T' || text[i] == 'n' || text[i] == 'N' || 
			text[i] == 'v' || text[i] == 'V' || text[i] == 'w' || text[i] == 'W' ||
			text[i] == 'x' || text[i] == 'X' || text[i] == 'y' || text[i] == 'Y' ||
			text[i] == 'z' || text[i] == 'Z'){
				konverterad.replace(0,1,text[i]);
				konverterad.replace(1,1,'o');
				konverterad.replace(2,1,text[i]);
				while(n<3){
					cout<<konverterad[n];
					n++;
				}
				n=0;
			}
		else
			cout<<text[i];
		i++;
	}

return 0;
}
make konverterad an empty string and append the characters instead of replacing them. You can use the += operator
Okey thanks:) i did think about that. But i thouht i would be bad programming becouse then the string would not have a fixed predetermined size, but increment in size as the program looped in search of consonants^.-.
Topic archived. No new replies allowed.