passing formatted string as argument???
-
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
-
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
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
-
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
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.