-1

我正在尝试制作一串DWORD类型变量。我怎样才能连接它们?

    char* string;
    DWORD a,b,c;

//abc will get some values here


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

1 回答 1

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 :)

附言。我已经用 g++4.8 测试过了

于 2014-03-18T17:43:13.153 回答