Click here to Skip to main content
15,896,207 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: std::string to char* Pin
T.RATHA KRISHNAN1-Jul-08 2:07
T.RATHA KRISHNAN1-Jul-08 2:07 
GeneralRe: std::string to char* Pin
toxcct1-Jul-08 2:19
toxcct1-Jul-08 2:19 
QuestionRe: std::string to char* Pin
T.RATHA KRISHNAN1-Jul-08 2:25
T.RATHA KRISHNAN1-Jul-08 2:25 
AnswerRe: std::string to char* Pin
toxcct1-Jul-08 2:43
toxcct1-Jul-08 2:43 
QuestionRe: std::string to char* Pin
CPallini1-Jul-08 2:27
mveCPallini1-Jul-08 2:27 
AnswerRe: std::string to char* Pin
Stephen Hewitt1-Jul-08 14:34
Stephen Hewitt1-Jul-08 14:34 
GeneralRe: std::string to char* Pin
CPallini1-Jul-08 21:26
mveCPallini1-Jul-08 21:26 
GeneralRe: std::string to char* Pin
Stephen Hewitt1-Jul-08 14:33
Stephen Hewitt1-Jul-08 14:33 
toxcct wrote:
const char* exeroot = path.c_str();
strcat(exeroot, "/");
strcat(exeroot, "CharacterAnimation.exe");


Bad advice. The buffer returned from c_str is const and thus can't be modified. And it's wrong to cast away the const as it's const for a reason: the buffer used by a std::string need not be contiguous memory. If this is the case calling c_str makes a temporary buffer and copies the non-contiguous memory blocks into one contiguous memory block for you. It is not required to copy the blocks back. Also your code is in serious danger of causing a buffer overrun (if you made it compile by casting away the const): how do you know how big the buffer is?

Anyway the correct way is simpler, safe, works, is portable and requires no casts:
std::string path = dtCore::GetDeltaRootPath();
path += "/CharacterAnimation.exe";
system(path.c_str());


Steve

GeneralRe: std::string to char* Pin
killabyte1-Jul-08 2:20
killabyte1-Jul-08 2:20 
GeneralRe: std::string to char* Pin
CPallini1-Jul-08 2:29
mveCPallini1-Jul-08 2:29 
GeneralRe: std::string to char* Pin
killabyte1-Jul-08 2:34
killabyte1-Jul-08 2:34 
GeneralRe: std::string to char* Pin
Stephen Hewitt1-Jul-08 14:42
Stephen Hewitt1-Jul-08 14:42 
GeneralRe: std::string to char* PinPopular
CPallini1-Jul-08 2:24
mveCPallini1-Jul-08 2:24 
QuestionRe: std::string to char* Pin
T.RATHA KRISHNAN1-Jul-08 2:39
T.RATHA KRISHNAN1-Jul-08 2:39 
AnswerRe: std::string to char* Pin
toxcct1-Jul-08 2:46
toxcct1-Jul-08 2:46 
GeneralRe: std::string to char* Pin
T.RATHA KRISHNAN1-Jul-08 2:54
T.RATHA KRISHNAN1-Jul-08 2:54 
GeneralRe: std::string to char* Pin
toxcct1-Jul-08 2:58
toxcct1-Jul-08 2:58 
GeneralRe: std::string to char* Pin
SandipG 1-Jul-08 3:11
SandipG 1-Jul-08 3:11 
GeneralRe: std::string to char* Pin
T.RATHA KRISHNAN1-Jul-08 3:20
T.RATHA KRISHNAN1-Jul-08 3:20 
GeneralRe: std::string to char* Pin
toxcct1-Jul-08 3:22
toxcct1-Jul-08 3:22 
GeneralRe: std::string to char* Pin
Mark Salsbery1-Jul-08 7:29
Mark Salsbery1-Jul-08 7:29 
GeneralRe: std::string to char* Pin
SandipG 1-Jul-08 3:08
SandipG 1-Jul-08 3:08 
GeneralRe: std::string to char* Pin
SandipG 1-Jul-08 2:56
SandipG 1-Jul-08 2:56 
AnswerRe: std::string to char* [modified] Pin
CPallini1-Jul-08 3:00
mveCPallini1-Jul-08 3:00 
GeneralRe: std::string to char* Pin
toxcct1-Jul-08 3:14
toxcct1-Jul-08 3:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.