User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 361,626 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,224 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 918 | Replies: 5 | Solved
Reply
Join Date: Jul 2007
Posts: 29
Reputation: linux0id is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
linux0id's Avatar
linux0id linux0id is offline Offline
Light Poster

how to insert variables into string with % sign?

  #1  
Feb 13th, 2008
Hello everyone!
I have seen some code where some variable gets inserted into string throught the % sign, like so -
("insert into songs values (%Q ,%d, %d, %Q, %Q, %Q, ... ", someInt, someChar, someChar... )
I have tried to look it up in google but I do not know what this is called. What is it and where can I find a reference for it? Thanks!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,457
Reputation: niek_e is a jewel in the rough niek_e is a jewel in the rough niek_e is a jewel in the rough 
Rep Power: 6
Solved Threads: 148
niek_e's Avatar
niek_e niek_e is offline Offline
Nearly a Posting Virtuoso

Re: how to insert variables into string with % sign?

  #2  
Feb 13th, 2008
("insert into songs values (%Q ,%d, %d, %Q, %Q, %Q, ... ", someInt, someChar, someChar... )

Do you use someting like sprintf_s()? (or sprintf())
example:
  1. char c = 'x';
  2. int i = 123;
  3. char buffer[1024];
  4. sprintf(buffer, "Test number: %d, test char, %c", i,c);
Last edited by niek_e : Feb 13th, 2008 at 3:48 am.
"= != =="

PM's asking for help will be ignored..
Reply With Quote  
Join Date: Jul 2007
Posts: 29
Reputation: linux0id is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
linux0id's Avatar
linux0id linux0id is offline Offline
Light Poster

Re: how to insert variables into string with % sign?

  #3  
Feb 13th, 2008
No, but I want to use this for sqlite3 to insert data into tables, like combine the "insert into" command with data. Do I have to "print" it to string and then use it? Thanks
Reply With Quote  
Join Date: Dec 2006
Location: india
Posts: 1,011
Reputation: vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light 
Rep Power: 9
Solved Threads: 152
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: how to insert variables into string with % sign?

  #4  
Feb 13th, 2008
> I have seen some code where some variable gets inserted into string through the % sign
the code you saw was probably using the Boost.Format library to insert stuff into a stringstream. http://www.boost.org/libs/format/doc/format.html
Last edited by vijayan121 : Feb 13th, 2008 at 5:36 am.
Reply With Quote  
Join Date: May 2006
Posts: 2,649
Reputation: WaltP is a name known to all WaltP is a name known to all WaltP is a name known to all WaltP is a name known to all WaltP is a name known to all WaltP is a name known to all 
Rep Power: 14
Solved Threads: 217
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: how to insert variables into string with % sign?

  #5  
Feb 13th, 2008
The string with the %x symbols in it are parsed to find each symbol. The letter is then looked at to figure out what field is supposed to go there. Then the string is changed by removing the %x and whatever field is requested replaces it.

Usually the data comes out of variables and/or structures the program has already read or generated.

There is no function to do this if that's what you're looking for. The function is written by the programmers developing the system.
I'm like a superhero, but without powers nor motivation.
Reply With Quote  
Join Date: Jul 2007
Posts: 29
Reputation: linux0id is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
linux0id's Avatar
linux0id linux0id is offline Offline
Light Poster

Re: how to insert variables into string with % sign?

  #6  
Feb 13th, 2008
its not the boost library, I had a look again - it is the sprintf function. Now I will look at the documentation.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 6:36 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC