PDA

Click to See Complete Forum and Search --> : How do I put a variable in a string?


Wynd
Feb 8th, 2001, 07:03 PM
I was trying to create a file, like:

CreateFile("C:\\windows\\desktop\\var.txt", ... );

but I can't figure out how to change "var" to whatever I want as in javascript you can do:

alert("hello, " +name+"!");

where "name" is an input, how can i do this in C++? Sorry if i am being incoherent, but i don't really know how to say it.

HarryW
Feb 8th, 2001, 07:28 PM
I know what you mean. You can do it using the very handy sprintf() function. I expect (hope) you've used printf() to print out variables and strings to a console window before, using a format string. sprintf() works exactly the same way, but you specify a destination string to print to as the first argument.