•
•
•
•
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
![]() |
Hello everyone!
I have seen some code where some variable gets inserted into string throught the % sign, like so -
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!
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... )•
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,457
Reputation:
Rep Power: 6
Solved Threads: 148
•
•
•
•
("insert into songs values (%Q ,%d, %d, %Q, %Q, %Q, ... ", someInt, someChar, someChar... )
Do you use someting like sprintf_s()? (or sprintf())
example:
c Syntax (Toggle Plain Text)
char c = 'x'; int i = 123; char buffer[1024]; 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..
PM's asking for help will be ignored..
•
•
Join Date: Dec 2006
Location: india
Posts: 1,011
Reputation:
Rep Power: 9
Solved Threads: 152
> 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
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.
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.
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.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: arrange
- Next Thread: @@Help with calling VC++ DLL from DEV C++@@



Linear Mode