使用DWORDS

时间:2014-03-18 17:33:36

标签: c++ dword

我正在尝试创建一个DWORD类型变量的字符串。我该如何连接它们?

    char* string;
    DWORD a,b,c;

//abc will get some values here


    strcat(string,a);
    strcat(string,b);
    strcat(string,c);

1 个答案:

答案 0 :(得分:2)

在c ++下你可以使用ostringstream:

#include<iostream>
#include <sstream>
int main() {
  std::ostringstream os;
  typedef unsigned long DWORD;
  DWORD dw1 = 1;
  DWORD dw2 = 2;
  DWORD dw3 = 2;
  os << dw1 << "," << dw2 << "," << dw3 << std::endl;
  std::cout << os.str();

  // os.str() returns std::string
  return 0;
}

您的示例代码表明您可能更喜欢C解决方案,如:

char str[256];
sprintf(str, "%ld %ld %ld", dw1, dw2, dw3);

std::cout << str; // this is of course c++ part :)

PS。我用g ++ 4.8

测试了这个