Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    String vs string

    SDK Help
    0
    9
    837
    Loading More Posts
    • 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
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 19/02/2004 at 03:47, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   8.100 
      Platform:   Windows  ;   
      Language(s) :     C++  ;

      ---------
      Hi all
      Can anyone tell me how to convert from String type (SDK) to c string type or the reverse side?
      Thanks in advance

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 19/02/2004 at 19:03, xxxxxxxx wrote:

        Do you mean the C++ std::string type or some other type? I don't think there's an explicit string type within C, only arrays of characters. (Like "const char[]".)
        Also, please see the other thread in the forum about GetCString() if this is what you're after.

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 20/02/2004 at 02:15, xxxxxxxx wrote:

          Yes this is std::string.
          Do u have any idea how to cast from std::string to SDK String ?
          Thanks and regards

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 22/02/2004 at 17:15, xxxxxxxx wrote:

            This would be one way:

                
                
                #include <string>
                
                
                
                
                std::string StringToStdString(const String& s, StringEncoding enc = StXbit)  
                {  
                  std::string r;  
                  const LONG len = s.GetCStringLen(enc);  
                  CHAR* tmp = new CHAR[len+1];  
                  if (tmp)   
                  {  
                    if (len == s.GetCString(tmp, len+1, enc))  
                    {  
                      r.assign(tmp);  
                    }  
                  }  
                  delete[] tmp;  
                  return r;  
                }
                
                
                
                
                String StdStringToString(const std::string& s, StringEncoding enc = StXbit)  
                {  
                  String r;  
                  const CHAR* tmp = s.c_str();  
                  if (tmp)  
                  {  
                    r.SetCString(tmp, -1, enc);  
                  }  
                  return r;  
                }
                
                
                
                
                Bool MenuTest::Execute(BaseDocument *doc)  
                {  
                  String s1 = "Hello World!";  
                  std::string s2 = StringToStdString(s1);  
                  String s3 = StdStringToString(s2);
                
                
                
                
                  GePrint(s3);  
                }
            
            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 22/02/2004 at 19:01, xxxxxxxx wrote:

              Hi Mikael
              Thanks for the reply.
              If i printed the CHAR First[51] using GeDebugOut, I will get this result: u)ü
              I am a bit lost not. Is That means i have to do like this:
              CHAR First[51];
              SQLBindCol (hStmt, 1, SQL_C_CHAR, First, sizeof(First), &cbModel);
              Seems like to get the String of First, I have tried to do it like:
              String s3 = String(First);
              But i got the same resule as above as u)ü when i used GePrint to print in the console?
              Any hints for me how to solve this?
              Thanks and regards

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 22/02/2004 at 19:44, xxxxxxxx wrote:

                Are you sure that SQLBindCol has actually put anything sensible into the string? If GeDebugOut() prints "u)ü" then I'd say it's pretty likely that's what is in memory.
                By using the debugger I didn't mean GeDebugOut(). Instead, place a breakpoint on the first line (F9 in MSVC), then run the plugin (F5 in MSVC) and see how the memory changes. (You have various debug panels. Check out the documentation of your IDE for more information.)

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                  On 22/02/2004 at 20:19, xxxxxxxx wrote:

                  I have tried using VC++, my code is:
                  CHAR First[5]
                  SQLBindCol (hStmt, 2, SQL_C_CHAR, First, sizeof(First), &cbModel);
                  then I casted it into c string
                  string str((const char* ) First);
                  printf("From the string object: %s\n", str.c_str());
                  When I printed into the console, I got the correct answer from database.
                  The problem occures when I tried to cast it into String from C4D, is it correct that I will get the encoded of the str above by using
                  String s3 = StdStringToString(str);
                  Thanks and regards

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                    On 22/02/2004 at 20:33, xxxxxxxx wrote:

                    Ok, then I trust you that SQLBindCol() is not the culprit. Do you mean that the function I provided above cannot correctly convert your std::string into a C4D String? That's very strange. Perhaps it's a zero termination issue. Could you try single stepping the code to see where it goes wrong? (Please tell me if you need help to set up your debug environment. Solving this problem without a debugger might be hard.)
                    Also, if the string doesn't contain any non-ASCII characters (which at this point sounds like a good thing to do to simplify the debugging), then you could try one of the simpler encodings, e.g. St7bit.
                    The code I posted above has been tested both in 8.503 and 8.207. You say that you're using 8.1, which is unsupported since 8.2 is a free update. I don't suspect that this would be the problem, but you should try updating to at least 8.2 anyway.

                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                      On 29/03/2007 at 03:07, xxxxxxxx wrote:

                      Mark~~~~~~~~~~

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post