我一直在与C++号星座合作,并试图装上<条码>,*条码>,载于<条码>以下: 采用C类功能,例如strcpy(
)。 自strcpy(
)起 <代码>*>*,作为参数,我必须投下如下内容:
std::string destination;
unsigned char *source;
strcpy((char*)destination.c_str(), (char*)source);
The code works fine and when I run the program in a debugger, the value of *source
is stored in destination
, but for some odd reason it won t print out with the statement
<代码>std:cout << Point;
我注意到,如果我使用的话
std:cout <<apac_str(>);
价值印本正确无误,所有价值都很好。 为什么发生这种情况? 是否有更好的方法将<条码>未签署文件*条码>或<条码>印成<条码>; 似乎只是在我指定一个复印操作中的“条码”(<>foo.c_str()”时才会发生。
Edit: To answer the question "why would you do this?", I am using strcpy()
as a plain example. There are other times that it s more complex than assignment. For example, having to copy only X amount of string A into string B using strncpy()
or passing a std::string
to a function from a C library that takes a char *
as a parameter for a buffer.