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. Other Discussions
  3. Clever Code
  4. iostream issue [modified]

iostream issue [modified]

Scheduled Pinned Locked Moved Clever Code
sysadmindebugginghelp
6 Posts 4 Posters 8 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.
  • R Offline
    R Offline
    Rama Krishna Vavilala
    wrote on last edited by
    #1

    I have committed this(ese) mistake several times. There are 2 problems with the code below.

    void Connect(LPCTSTR szServer, LPCTSTR szUser, LPCTSTR szPassword)
    {
    std::stringstream ss;
    ss << "Server = " << szServer
    << "User = " << szUser
    << "; Password = " << szPassword;

    Ext_ConnectToDatabase(ss.str().c_str());
    }

    //Some external library has following sig
    void Ext_ConnectToDatabase(const char* szConnectString);

    -- modified at 9:59 Thursday 28th September, 2006


    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

    S L 2 Replies Last reply
    0
    • R Rama Krishna Vavilala

      I have committed this(ese) mistake several times. There are 2 problems with the code below.

      void Connect(LPCTSTR szServer, LPCTSTR szUser, LPCTSTR szPassword)
      {
      std::stringstream ss;
      ss << "Server = " << szServer
      << "User = " << szUser
      << "; Password = " << szPassword;

      Ext_ConnectToDatabase(ss.str().c_str());
      }

      //Some external library has following sig
      void Ext_ConnectToDatabase(const char* szConnectString);

      -- modified at 9:59 Thursday 28th September, 2006


      Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

      S Offline
      S Offline
      Stephan Pilz
      wrote on last edited by
      #2

      One little bu should be the missing semicolon in the result stream between szServer und "User". c_str() returns a const char*. Maybe the external lib want modify the char* getting through parameter ?

                     \\\\\\|///
                   \\\\  - -  //
                    (  @ @  )
      

      +---------------oOOo-(_)-oOOo-----------------+
      | Stephan Pilz stephan.pilz@stephan-pilz.de |
      | www.stephan-pilz.de |
      | ICQ#: 127823481 |
      +-----------------------Oooo------------------+
      oooO ( )
      ( ) ) /
      \ ( (_/
      \_)

      R 1 Reply Last reply
      0
      • R Rama Krishna Vavilala

        I have committed this(ese) mistake several times. There are 2 problems with the code below.

        void Connect(LPCTSTR szServer, LPCTSTR szUser, LPCTSTR szPassword)
        {
        std::stringstream ss;
        ss << "Server = " << szServer
        << "User = " << szUser
        << "; Password = " << szPassword;

        Ext_ConnectToDatabase(ss.str().c_str());
        }

        //Some external library has following sig
        void Ext_ConnectToDatabase(const char* szConnectString);

        -- modified at 9:59 Thursday 28th September, 2006


        Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

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

        It isn't Unicode friendly, but I don't know if that is relevant. You are using TCHAR friendly params to Connect, but then you use the ASCII stringstream function. With a Unicode build, this isn't going to work is it? You would need to use std::wstringstream, or, better still, something like std::basic_stringstream<TCHAR>. Also, the Ex_ConnectToDatabase function takes a char* and std::stringstream::str().c_str() returns a const char*.


        Kicking squealing Gucci little piggy.

        R 1 Reply Last reply
        0
        • S Stephan Pilz

          One little bu should be the missing semicolon in the result stream between szServer und "User". c_str() returns a const char*. Maybe the external lib want modify the char* getting through parameter ?

                         \\\\\\|///
                       \\\\  - -  //
                        (  @ @  )
          

          +---------------oOOo-(_)-oOOo-----------------+
          | Stephan Pilz stephan.pilz@stephan-pilz.de |
          | www.stephan-pilz.de |
          | ICQ#: 127823481 |
          +-----------------------Oooo------------------+
          oooO ( )
          ( ) ) /
          \ ( (_/
          \_)

          R Offline
          R Offline
          Rama Krishna Vavilala
          wrote on last edited by
          #4

          Stephan Pilz wrote:

          c_str() returns a const char*.

          Sorry for the typo, it is not a compilation issue. I corrected the call to external lib. The external lib accepts const char*.


          Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

          1 Reply Last reply
          0
          • L Lost User

            It isn't Unicode friendly, but I don't know if that is relevant. You are using TCHAR friendly params to Connect, but then you use the ASCII stringstream function. With a Unicode build, this isn't going to work is it? You would need to use std::wstringstream, or, better still, something like std::basic_stringstream<TCHAR>. Also, the Ex_ConnectToDatabase function takes a char* and std::stringstream::str().c_str() returns a const char*.


            Kicking squealing Gucci little piggy.

            R Offline
            R Offline
            Rama Krishna Vavilala
            wrote on last edited by
            #5

            Rob Caldecott wrote:

            With a Unicode build, this isn't going to work is it?

            That's the issue. With UNICODE build ss << szServer writes the pointer value to the stream. The compilation always succeeds. To solve that I had to add overload the operator << for streams for wchar_t.

            Rob Caldecott wrote:

            Also, the Ex_ConnectToDatabase function takes a char* and std::stringstream::str().c_str() returns a const char*.

            That was a typo.:-O


            Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

            Z 1 Reply Last reply
            0
            • R Rama Krishna Vavilala

              Rob Caldecott wrote:

              With a Unicode build, this isn't going to work is it?

              That's the issue. With UNICODE build ss << szServer writes the pointer value to the stream. The compilation always succeeds. To solve that I had to add overload the operator << for streams for wchar_t.

              Rob Caldecott wrote:

              Also, the Ex_ConnectToDatabase function takes a char* and std::stringstream::str().c_str() returns a const char*.

              That was a typo.:-O


              Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

              Z Offline
              Z Offline
              Zac Howland
              wrote on last edited by
              #6

              You could always force the input for the connect function to be const char*'s instead of const TCHAR*'s. Of course, that only pushes it back a level, but then at least it is more clear.

              If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

              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