bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C++ String to C buffer


From: verfranc
Subject: C++ String to C buffer
Date: Sun, 11 Jun 2006 01:03:51 -0700 (PDT)

Hi, I have a C++ program compiled under g++ 4. This program was running good when it was compiled under g++ 3. Under g++ 4, this program exits w/o any error msg. I have traced the code that caused this problem. The code is : ... char myInput[100]; ... string strInput = "1234567890abcdefg"; ... memset(myInput, '\0', 100); strcpy((char*)myInput, strInput.c_str()); // This is where it hangs or exits ... So I successfully re-code this to : ... unsigned char* myInput; ... string strInput = "1234567890abcdefg"; ... myInput = (unsigned char*)mallac(100); if (!myInput) { return; } memset(myInput, '\0', 100); strcpy((char*)myInput, strInput.c_str()); ... Is it not right to copy a C++ String to a C buffer? What's the difference if I copy a C++ String to a pointer to a string? By the way, I have compiled the above code using the default parameters of g++. Thanks, Van

View this message in context: C++ String to C buffer
Sent from the Gnu - Common C++ forum at Nabble.com.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]