I have overloaded >>
for my myString class. But, when I use cin >> temp
and after that I use another cin for a string it seems that other cin s does not work like before.
If you look to my code, I mean that the program does not understand y or n in the end and always is in the while loop.
this is istream function (a friend for myString class)
std::istream &operator>> (std::istream& input, myString& str) {
char* temp = new char [1000];
input >> temp;
int i=0;
int pow2=1;
for (i; temp[i]!=NULL; i++) {
while(pow2<=i)
pow2 *= 2;
}
delete [] str.string_;
str.length = i;
str.capacity = pow2;
str.string_ = new char [pow2];
for (int i=0; i<str.length; i++)
str.string_[i] = temp[i];
delete [] temp;
return input;
}
This is main
cout << "myString Program" << endl;
while(1) { //simple again or not while
myString c;
cin >> c;
cout << c;
string input;
cout << "\nCountine (y/n)?";
getline(cin, input);
if (input[0] == 'n' || input[0] == 'N')
break;
}