Question

I am trying to make a string of DWORD type variables. How can I concatenate them?

    char* string;
    DWORD a,b,c;

//abc will get some values here


    strcat(string,a);
    strcat(string,b);
    strcat(string,c);
Was it helpful?

Solution

Under c++ you can use 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;
}

your sample code indicates that you might prefer C solution like:

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

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

ps. I have tested this with g++4.8

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top