LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   string format question (https://www.linuxquestions.org/questions/programming-9/string-format-question-786685/)

HarryBoy 02-03-2010 09:32 AM

string format question
 
I am using C.
I have a fuction that returns a string
Code:

std::string name = getstingValue();
I need to format this string so that I can create a text file like so:

So I'm trying:
Code:

std::string newfilepath;
sprintf(newfilepath, "//myfolder//myfiles//%s", filename);
std::ofstream myfile(newfilepath.c_str());

But I get errors like:
cannot convert ‘std::string’ to ‘char*’ for argument ‘1’ to ‘int sprintf(char*, const char*, ...)’


How can I deal with this?

carbonfiber 02-03-2010 10:16 AM

Quote:

Originally Posted by HarryBoy (Post 3850869)
I am using C.

No you're not.

Quote:

How can I deal with this?
Learn the difference between char * and std::string.

smeezekitty 02-03-2010 04:38 PM

Code:

std::string newfilepath;
newfilepath=("//myfolder//myfiles//");
newfilepath+=filename;



All times are GMT -5. The time now is 10:39 AM.