LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-03-2010, 09:32 AM   #1
HarryBoy
Member
 
Registered: Apr 2008
Distribution: MontaVista Linux Version 4.0.1, Professional Edition
Posts: 215

Rep: Reputation: 16
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?
 
Old 02-03-2010, 10:16 AM   #2
carbonfiber
Member
 
Registered: Sep 2009
Location: Sparta
Posts: 237

Rep: Reputation: 46
Quote:
Originally Posted by HarryBoy View Post
I am using C.
No you're not.

Quote:
How can I deal with this?
Learn the difference between char * and std::string.
 
Old 02-03-2010, 04:38 PM   #3
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Code:
std::string newfilepath;
newfilepath=("//myfolder//myfiles//");
newfilepath+=filename;

Last edited by smeezekitty; 02-03-2010 at 04:44 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting time with specific format string MS3FGX Linux - Software 5 09-21-2009 04:50 PM
Converting time from string to long format Deepak Inbasekaran Programming 6 07-21-2006 05:00 PM
Quick String Format Question (EASY) Mistro116@yahoo.com Programming 1 11-27-2005 02:09 PM
How to format this string bahadur Programming 1 03-26-2005 03:03 AM
convert date time format given in string suchi_s Programming 6 01-10-2005 04:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration