Results 1 to 2 of 2

Thread: How do I put a variable in a string?

  1. #1

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    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.
    Alcohol & calculus don't mix.
    Never drink & derive.

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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.
    Harry.

    "From one thing, know ten thousand things."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width