如何将DWORD转换为char*
How to convert DWORD to char *?
我正在尝试这样的东西,
PROCESS_INFORMATION processInfo = .....
strcat( args, processInfo.dwProcessId);
其中CCD_ 1是CCD_ 2,我需要将其作为参数传递给另一个可执行文件。
您可以使用sprintf
char procID[10];
sprintf(procID, "%d", processInfo.dwProcessId);
这将把processInfo.dwProcessId转换成一个可以供您使用的字符。
要将DWORD转换为char*,可以使用_ultoa/ultoa_s
请参阅此处可能会对您有所帮助。link1
MSDN有非常好的文档,请查看数据转换页面。
还有sprintf()。
虽然不直接"转换为char*
",但以下操作应该可以实现:
std::ostringstream stream;
stream << processInfo.dwProcessId;
std::string args = stream.str();
// Then, if you need a 'const char*' to pass to another Win32
// API call, you can access the data using:
const char * foo = args.c_str();
相关文章:
- 将无符号char*转换为std::istream*C++
- 为什么这个函数将"const char*"转换为"void* const"而不是"const void*"
- 将函数参数"const char*"转换为"std::string_view"是
- C ++如何在使用"tolower"时将char转换为int
- 有没有办法在C++的赋值中将"char**"转换为"double"?
- JavaCPP 错误:无法将参数"1"的"char*"转换为"Abc*
- 为什么从 char 转换为 std::byte 可能是未定义的行为?
- 如何在虚幻引擎4中将char*转换为TCHAR?
- C++:将模板类型 char 转换为 std::string
- strcmp/char* 转换无法按预期工作
- C++中的SQLite char*转换
- 无法从 const char* 转换为 const char *&
- 在 C++ 中将 char 转换为 int,而无需符号位传播
- 如果必须包含西里尔字符,如何将 char* 转换为 std::string?
- 试图使用strCMP时的char转换错误
- 无法从'const char *'转换为'LPCTSTR'
- 将 std::vector<char> 转换为字符* 会导致字符缺陷
- 使用 static_cast 将 char 转换为 int c++
- 如何在 C++(MFC) 中将 char* 转换为 LPCTSTR
- 无法将const char转换为字符串构造字符串