Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. string problem???

string problem???

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hackC
    wrote on last edited by
    #1

    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

    M D 2 Replies Last reply
    0
    • H hackC

      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

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      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

      H 1 Reply Last reply
      0
      • M Maximilien

        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

        H Offline
        H Offline
        hackC
        wrote on last edited by
        #3

        Would <= and >= fix the problem? If not what would I have to put there?

        R M 2 Replies Last reply
        0
        • H hackC

          Would <= and >= fix the problem? If not what would I have to put there?

          R Offline
          R Offline
          RobJones
          wrote on last edited by
          #4

          if(a.size() > b.size()) { .... } if(a.size() < b.size()) { .... } if you are compairing the lengths. Whoever said nothing's impossible never tried slamming a revolving door!

          1 Reply Last reply
          0
          • H hackC

            Would <= and >= fix the problem? If not what would I have to put there?

            M Offline
            M Offline
            Maximilien
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • H hackC

              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

              D Offline
              D Offline
              Demonware666
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups