string problem???
-
When i enter the words rents and will the program will say "will is larger than rents" which is wrong. I can't figure out why it's doing that. I supplied the code below (might have forgot little things like ; or ,). If anyone can tell me what is wrong it would help me a lot. I'm new to C++ programming. #include #include using namespace std; int main() { string a, b; cout << "Enter two words." << endl; cin >> a >> b; cin.ignore(10,'\n'); string small, big; if (a < b) { small = a; big = b; } if (a > b) { small = b; big = a; } if (a.size() == b.size() && a != b)) { cout << "Same size, but different string" << endl; cin.get(); return 0; } if (a == b) { cout << "Their the same string" << endl; cin.get(); return 0; } cout << big << " is larger than " << small << endl; cin.get(); return 0; } -- modified at 13:53 Friday 10th February, 2006
-
When i enter the words rents and will the program will say "will is larger than rents" which is wrong. I can't figure out why it's doing that. I supplied the code below (might have forgot little things like ; or ,). If anyone can tell me what is wrong it would help me a lot. I'm new to C++ programming. #include #include using namespace std; int main() { string a, b; cout << "Enter two words." << endl; cin >> a >> b; cin.ignore(10,'\n'); string small, big; if (a < b) { small = a; big = b; } if (a > b) { small = b; big = a; } if (a.size() == b.size() && a != b)) { cout << "Same size, but different string" << endl; cin.get(); return 0; } if (a == b) { cout << "Their the same string" << endl; cin.get(); return 0; } cout << big << " is larger than " << small << endl; cin.get(); return 0; } -- modified at 13:53 Friday 10th February, 2006
will is larger than rents ... the < or > compare lexicographically; so W is bigger than R. anyway, in my case, my will will be bigger than my rent ... :->
Maximilien Lincourt Your Head A Splode - Strong Bad
-
will is larger than rents ... the < or > compare lexicographically; so W is bigger than R. anyway, in my case, my will will be bigger than my rent ... :->
Maximilien Lincourt Your Head A Splode - Strong Bad
-
no it will not. R is still smaller ( or equal ) than W, whatever the length of the rest of the strings. what are you trying to compare ? the string length ? or the lexical order ?
Maximilien Lincourt Your Head A Splode - Strong Bad
-
When i enter the words rents and will the program will say "will is larger than rents" which is wrong. I can't figure out why it's doing that. I supplied the code below (might have forgot little things like ; or ,). If anyone can tell me what is wrong it would help me a lot. I'm new to C++ programming. #include #include using namespace std; int main() { string a, b; cout << "Enter two words." << endl; cin >> a >> b; cin.ignore(10,'\n'); string small, big; if (a < b) { small = a; big = b; } if (a > b) { small = b; big = a; } if (a.size() == b.size() && a != b)) { cout << "Same size, but different string" << endl; cin.get(); return 0; } if (a == b) { cout << "Their the same string" << endl; cin.get(); return 0; } cout << big << " is larger than " << small << endl; cin.get(); return 0; } -- modified at 13:53 Friday 10th February, 2006
I once had a similiar problem so I used the strcmp function. Check out digitalmars.com for the details on dealing with strings, its a great site. Got to the runtime library part. ALL YOUR BASE ARE BELONG TO MICROSOFT! Demonware Studios Leader