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 do I...

How do I...

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
9 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.
  • K Offline
    K Offline
    KORCARI
    wrote on last edited by
    #1

    Can you tell me please how to pass strings as parameters of a function so we can use them for different purposes?Please help me !!!!

    D 1 Reply Last reply
    0
    • K KORCARI

      Can you tell me please how to pass strings as parameters of a function so we can use them for different purposes?Please help me !!!!

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      void foo1( LPCTSTR lpszName )
      {
      // do something with lpszName
      }

      or

      void foo2( CString &strName )
      {
      // do something with strName
      }
      ...
      foo1("My name is...");
      CString str("Bob");
      foo2(str);


      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      C 1 Reply Last reply
      0
      • D David Crow

        void foo1( LPCTSTR lpszName )
        {
        // do something with lpszName
        }

        or

        void foo2( CString &strName )
        {
        // do something with strName
        }
        ...
        foo1("My name is...");
        CString str("Bob");
        foo2(str);


        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        you forgot: include using std::string void foo3( string s) { } not to mention char *. Is LPCTSTR a macro that converts to narrow and wide strings ? Then there's BSTR and bstr_t...... Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

        D D 2 Replies Last reply
        0
        • C Christian Graus

          you forgot: include using std::string void foo3( string s) { } not to mention char *. Is LPCTSTR a macro that converts to narrow and wide strings ? Then there's BSTR and bstr_t...... Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

          D Offline
          D Offline
          DaFrawg
          wrote on last edited by
          #4

          I guess it's better to replace using std::string; by using namespace std; or else the class 'string' will not be available (it's 'std::string', not 'std::string::string'). LPCTSTR is not really a macro: #define LPCTSTR const char* (or something like that, I probably forgot the As and Ws for ANSI and Unicode)

          C 1 Reply Last reply
          0
          • D DaFrawg

            I guess it's better to replace using std::string; by using namespace std; or else the class 'string' will not be available (it's 'std::string', not 'std::string::string'). LPCTSTR is not really a macro: #define LPCTSTR const char* (or something like that, I probably forgot the As and Ws for ANSI and Unicode)

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            DaFrawg wrote: I guess it's better to replace using std::string; by using namespace std; Nope, that's rubbish. That scopes all of namespace std unnecessarily, if std::string is all that is wanted. DaFrawg wrote: or else the class 'string' will not be available (it's 'std::string', not 'std::string::string'). You're completely wrong here. I don't even know how you ended up with this theory. DaFrawg wrote: LPCTSTR is not really a macro: #define LPCTSTR const char* (or something like that, I probably forgot the As and Ws for ANSI and Unicode) That is, by definition, a macro, just a parameterless one. Thanks for playing tho. :-) Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

            D 1 Reply Last reply
            0
            • C Christian Graus

              you forgot: include using std::string void foo3( string s) { } not to mention char *. Is LPCTSTR a macro that converts to narrow and wide strings ? Then there's BSTR and bstr_t...... Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Christian Graus wrote: you forgot: Technically speaking, yes. Since STL and Unicode are not part of my normal development paradigm, I don't often think of them.


              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              C 1 Reply Last reply
              0
              • D David Crow

                Christian Graus wrote: you forgot: Technically speaking, yes. Since STL and Unicode are not part of my normal development paradigm, I don't often think of them.


                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                *grin* To be honest, Unicode has never figured highly in my thoughts either. But I was always an STL junkie :-) Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

                1 Reply Last reply
                0
                • C Christian Graus

                  DaFrawg wrote: I guess it's better to replace using std::string; by using namespace std; Nope, that's rubbish. That scopes all of namespace std unnecessarily, if std::string is all that is wanted. DaFrawg wrote: or else the class 'string' will not be available (it's 'std::string', not 'std::string::string'). You're completely wrong here. I don't even know how you ended up with this theory. DaFrawg wrote: LPCTSTR is not really a macro: #define LPCTSTR const char* (or something like that, I probably forgot the As and Ws for ANSI and Unicode) That is, by definition, a macro, just a parameterless one. Thanks for playing tho. :-) Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

                  D Offline
                  D Offline
                  DaFrawg
                  wrote on last edited by
                  #8

                  Christian Graus wrote: Nope, that's rubbish. That scopes all of namespace std unnecessarily, if std::string is all that is wanted. Sorry, I didn't know that there was something like "using Declaration". MSDN: "The using declaration introduces a name into the declarative region in which the using declaration appears." :-O Christian Graus wrote: That is, by definition, a macro, just a parameterless one. Tell that the people who claim they are called "symbolic identifiers". :rolleyes:

                  C 1 Reply Last reply
                  0
                  • D DaFrawg

                    Christian Graus wrote: Nope, that's rubbish. That scopes all of namespace std unnecessarily, if std::string is all that is wanted. Sorry, I didn't know that there was something like "using Declaration". MSDN: "The using declaration introduces a name into the declarative region in which the using declaration appears." :-O Christian Graus wrote: That is, by definition, a macro, just a parameterless one. Tell that the people who claim they are called "symbolic identifiers". :rolleyes:

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #9

                    DaFrawg wrote: Sorry, I didn't know that there was something like "using Declaration". NP. Glad to help you learn somethng new. The using declaration is better because you control what gets pulled into global scope. Otherwise, you have no real idea. DaFrawg wrote: Tell that the people who claim they are called "symbolic identifiers". They just say that because macros are evil, but a rose by any other name.... Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

                    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