Custom input stream function

Hello there, i am currently working on a custom istream function for a school assignment but i am not quite sure if i am heading towards the right direction or if it can be improved in any other way. If you have any comments or i made some mistakes, feel free to point them out. Thanks!

- User is able to key in 3 lines of text and it would be concatenated into a single string. Enter keypress are replaced by empty space.

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
istream & operator>> (istream & is, MyString & aMyString)
{	
        int tries = 3; 
	char buffer[200] = {'\0'};
	aMyString.Clear();

	do
	{
	        do
		{	
			is.get(buffer, 200);
			if(is.peek() != '\n')
                        {
			    aMyString.Append(buffer);			
                        }
                        else
                        {
                            tries -= 1;
                            if(tries > 0)
                            {
                                 aMyString.Append(" ");
                            }
                        }
		}while ((int)strlen(buffer) == 199);
	}while (tries > 0)
		
	is.sync();
	return is;
}
ShiHao
UAT Student
Last edited on
Topic archived. No new replies allowed.