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. How to egalise two strings

How to egalise two strings

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
41 Posts 11 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.
  • L Lost User

    Et cela pose problème? :doh:

    T Offline
    T Offline
    toxcct
    wrote on last edited by
    #23

    pourquoi tu le prend comme ca ? je le signalais juste à celui qui te répondait que son code ne marche que si ce sont des char*, pas des strings :~


    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

    C L 2 Replies Last reply
    0
    • T toxcct

      pourquoi tu le prend comme ca ? je le signalais juste à celui qui te répondait que son code ne marche que si ce sont des char*, pas des strings :~


      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #24

      OK, ragazzi, ora, rilassatevi...:-D

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      T 1 Reply Last reply
      0
      • T toxcct

        pourquoi tu le prend comme ca ? je le signalais juste à celui qui te répondait que son code ne marche que si ce sont des char*, pas des strings :~


        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #25

        Oula je ne suis pas du tout enervé, choqué, ou autre. Je bois les paroles de tous ceux qui postent un message sur ce forum car je n´ai a mon actif ke 30h de langage c++. Je n´y connais pas grand chose. :) Je suis actuellement en stage et je dois realiser ce programme. Cela fait maintenant une semaine que je suis dessus, et je sens qu´il est tout près d´aboutir. Désolé si ma réponse a pu paraitre sèche, ce n´etait pas du tout l´esprit du message. C´est l´effet message ecrit qui ne transcrit pas le ton de la voix. :)

        T R 2 Replies Last reply
        0
        • C CPallini

          OK, ragazzi, ora, rilassatevi...:-D

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #26

          uhh, sorry, i don't understand much italian ! lol


          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

          C 1 Reply Last reply
          0
          • L Lost User

            Oula je ne suis pas du tout enervé, choqué, ou autre. Je bois les paroles de tous ceux qui postent un message sur ce forum car je n´ai a mon actif ke 30h de langage c++. Je n´y connais pas grand chose. :) Je suis actuellement en stage et je dois realiser ce programme. Cela fait maintenant une semaine que je suis dessus, et je sens qu´il est tout près d´aboutir. Désolé si ma réponse a pu paraitre sèche, ce n´etait pas du tout l´esprit du message. C´est l´effet message ecrit qui ne transcrit pas le ton de la voix. :)

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #27

            ok, let's continue in english now. you still didn't answered a question of mine... what, for you, is the difference between equalize and compare 2 strings ?


            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

            L 1 Reply Last reply
            0
            • T toxcct

              ok, let's continue in english now. you still didn't answered a question of mine... what, for you, is the difference between equalize and compare 2 strings ?


              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #28

              to me, compare is looking at 2 objects and see if they are equal or not. egalise a and b is a=b (change the value of a or b so that it is equal to the other value) is it clear :doh:

              T 1 Reply Last reply
              0
              • T toxcct

                uhh, sorry, i don't understand much italian ! lol


                [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #29

                Oh, pardon, I assumed it was a multi-ethnic thread... :-D

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                1 Reply Last reply
                0
                • L Lost User

                  to me, compare is looking at 2 objects and see if they are equal or not. egalise a and b is a=b (change the value of a or b so that it is equal to the other value) is it clear :doh:

                  T Offline
                  T Offline
                  toxcct
                  wrote on last edited by
                  #30

                  ok, i get what's your problem then... you are trying to speak english with french words ;P don't say equalize but assign. anyway, as you're using std::strings, just use the = operator for this, and == operator to compare their content.

                  std::string s1 = "Hello";
                  std::string s2 = "World";

                  ASSERT(s1 != s2); // the objects contain different strings

                  s1 = s2; //Assign s2 content into s1
                  ASSERT(s1 == s2); // the objects contain same strings


                  [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                  L 1 Reply Last reply
                  0
                  • T toxcct

                    ok, i get what's your problem then... you are trying to speak english with french words ;P don't say equalize but assign. anyway, as you're using std::strings, just use the = operator for this, and == operator to compare their content.

                    std::string s1 = "Hello";
                    std::string s2 = "World";

                    ASSERT(s1 != s2); // the objects contain different strings

                    s1 = s2; //Assign s2 content into s1
                    ASSERT(s1 == s2); // the objects contain same strings


                    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #31

                    OK, just to see if i have caught what you said: I should use == to compare if string s1 has the same content with string s2. That´s it? Because I already have tried that and it doesn´t work...:((

                    L T 2 Replies Last reply
                    0
                    • L Lost User

                      OK, just to see if i have caught what you said: I should use == to compare if string s1 has the same content with string s2. That´s it? Because I already have tried that and it doesn´t work...:((

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #32

                      Hum ... i did a mistake while typing the code, i always typed: if(s1==s2) but the thing i wanted to check is if (s1!=s2) I am so sorry for the loss of time.... :| Anyway, thank you very much for your help!!!

                      1 Reply Last reply
                      0
                      • L Lost User

                        OK, just to see if i have caught what you said: I should use == to compare if string s1 has the same content with string s2. That´s it? Because I already have tried that and it doesn´t work...:((

                        T Offline
                        T Offline
                        toxcct
                        wrote on last edited by
                        #33

                        garfaoui wrote:

                        I should use == to compare if string s1 has the same content with string s2. That´s it?

                        exactly. but be careful, the operator must be the overload of std::string class. in the expression s1 == s2, if s1 is of type std::string, the code actually means to the compiler s1.operator==(s2) (calling then the function bool std::string::operator==(const std::string&)). but if s1 is a basic C-Style string (a char* basically), the compiler will try to compare the addresses, not the string contents... the context is exactly the same while using the operator != . so, can you please post a relevant (but small) piece of code which can reproduce the error ? also, specify to us the type of all the variables used, and which error you get (if it is a compiler error, linker error, or run-time error), and its message.


                        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                        1 Reply Last reply
                        0
                        • L Lost User

                          Hello, I would like to compare two strings: i used: if (s1==s2) { I have no problem to compile, but even when s1=s2 it doesnt work...

                          S Offline
                          S Offline
                          ShilpiP
                          wrote on last edited by
                          #34

                          string s1 = "shilpi"; string s2 = "shilpi"; if(strcmp(s1.c_str(),s2.c_str())==0) { printf("Hi"); } what i wanna say is this ,try it

                          Yes U Can ...If U Can ,Dream it , U can do it ...ICAN

                          1 Reply Last reply
                          0
                          • L Lost User

                            Oula je ne suis pas du tout enervé, choqué, ou autre. Je bois les paroles de tous ceux qui postent un message sur ce forum car je n´ai a mon actif ke 30h de langage c++. Je n´y connais pas grand chose. :) Je suis actuellement en stage et je dois realiser ce programme. Cela fait maintenant une semaine que je suis dessus, et je sens qu´il est tout près d´aboutir. Désolé si ma réponse a pu paraitre sèche, ce n´etait pas du tout l´esprit du message. C´est l´effet message ecrit qui ne transcrit pas le ton de la voix. :)

                            R Offline
                            R Offline
                            Rage
                            wrote on last edited by
                            #35

                            Francais et en stage au Portugal ?

                            Don't follow any man spiritually, don't do anything that will get you in sh*t if god is real - Bradml[^]

                            L 1 Reply Last reply
                            0
                            • R Rage

                              Francais et en stage au Portugal ?

                              Don't follow any man spiritually, don't do anything that will get you in sh*t if god is real - Bradml[^]

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #36

                              tout a fait =):-D

                              R 1 Reply Last reply
                              0
                              • L Lost User

                                tout a fait =):-D

                                R Offline
                                R Offline
                                Rage
                                wrote on last edited by
                                #37

                                Te laisse pas impressioner par Tox, il est dur, mais très très fort. ;P

                                Don't follow any man spiritually, don't do anything that will get you in sh*t if god is real - Bradml[^]

                                L 1 Reply Last reply
                                0
                                • R Rage

                                  Te laisse pas impressioner par Tox, il est dur, mais très très fort. ;P

                                  Don't follow any man spiritually, don't do anything that will get you in sh*t if god is real - Bradml[^]

                                  L Offline
                                  L Offline
                                  Lost User
                                  wrote on last edited by
                                  #38

                                  Ne t´inquète pas! En tout cas il m´a bien aidé! C´est par rapport au repertoire de l´executable que tu as vu que j´étais au Portugal?

                                  T R 2 Replies Last reply
                                  0
                                  • L Lost User

                                    Ne t´inquète pas! En tout cas il m´a bien aidé! C´est par rapport au repertoire de l´executable que tu as vu que j´étais au Portugal?

                                    T Offline
                                    T Offline
                                    toxcct
                                    wrote on last edited by
                                    #39

                                    non, par rapport a ton profil ^^ @Régis, merci pr la petite note d'humour... "il est tres tres fort", c'est a double tranchant ca ;P


                                    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                                    R 1 Reply Last reply
                                    0
                                    • L Lost User

                                      Ne t´inquète pas! En tout cas il m´a bien aidé! C´est par rapport au repertoire de l´executable que tu as vu que j´étais au Portugal?

                                      R Offline
                                      R Offline
                                      Rage
                                      wrote on last edited by
                                      #40

                                      Nope, c'est dans ta biographie (clique sur l'icone en forme de tete a cote de ton nom)

                                      Don't follow any man spiritually, don't do anything that will get you in sh*t if god is real - Bradml[^]

                                      1 Reply Last reply
                                      0
                                      • T toxcct

                                        non, par rapport a ton profil ^^ @Régis, merci pr la petite note d'humour... "il est tres tres fort", c'est a double tranchant ca ;P


                                        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                                        R Offline
                                        R Offline
                                        Rage
                                        wrote on last edited by
                                        #41

                                        ;)

                                        Don't follow any man spiritually, don't do anything that will get you in sh*t if god is real - Bradml[^]

                                        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