Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. passing formatted string as argument???

passing formatted string as argument???

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hearties
    wrote on last edited by
    #1

    Is it possible to pass formatted string to functions? //function prototype void find(CString s, int n); //code 1 //this is what I want to implement find("0=", nLevel); // do something find("1=", nLevel); // do something find("2=", nLevel); // do something // code2 // to implement the above in a for loop // can I do something like this? for (i = 0, i<=3, i++) { //blah blah find("%d=" i, nLevel); // blah blah } code 2 obviously doesnt work, but is there any other way I can implement code 1? pls help :-D

    I D 2 Replies Last reply
    0
    • H hearties

      Is it possible to pass formatted string to functions? //function prototype void find(CString s, int n); //code 1 //this is what I want to implement find("0=", nLevel); // do something find("1=", nLevel); // do something find("2=", nLevel); // do something // code2 // to implement the above in a for loop // can I do something like this? for (i = 0, i<=3, i++) { //blah blah find("%d=" i, nLevel); // blah blah } code 2 obviously doesnt work, but is there any other way I can implement code 1? pls help :-D

      I Offline
      I Offline
      Igor Sukhov
      wrote on last edited by
      #2

      Hi ! Try this: void find(CString& s, int n); for (i = 0, i<=3, i++) { //blah blah CString str ; str.Format("%d", i); find(str, nLevel); // blah blah } =========================== Is it possible to pass formatted string to functions? //function prototype void find(CString s, int n); //code 1 //this is what I want to implement find("0=", nLevel); // do something find("1=", nLevel); // do something find("2=", nLevel); // do something // code2 // to implement the above in a for loop // can I do something like this? for (i = 0, i<=3, i++) { //blah blah find("%d=" i, nLevel); // blah blah } code 2 obviously doesnt work, but is there any other way I can implement code 1? Best regards, ----------- Igor Soukhov (Brainbench/Tekmetrics ID:50759) igor_soukhov@mailru.com | ICQ:57404554 | http://siv.da.ru

      1 Reply Last reply
      0
      • H hearties

        Is it possible to pass formatted string to functions? //function prototype void find(CString s, int n); //code 1 //this is what I want to implement find("0=", nLevel); // do something find("1=", nLevel); // do something find("2=", nLevel); // do something // code2 // to implement the above in a for loop // can I do something like this? for (i = 0, i<=3, i++) { //blah blah find("%d=" i, nLevel); // blah blah } code 2 obviously doesnt work, but is there any other way I can implement code 1? pls help :-D

        D Offline
        D Offline
        David Fedolfi
        wrote on last edited by
        #3

        try something like: void findV (LPCSTR szFormat, int nLevel,...) { va_list argList; va_start(arglist, nLevel); CString str; str.FormatV (szFormat, argList); va_end(argList); find(str, nLevel); } you can then do for (int x =0; x<3; x++) { findV("%d=", nLevel, x); } The nLevel in there makes it kind of odd. If this is an out parameter you might want to change it to a return value.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups