Solved

fprintf error

Posted on 2004-09-07
2
420 Views
Last Modified: 2008-03-10
I'm trying to write the value of curCommand into the file pointed to by m_file.
The type of curCommand is String.

When I run the program using the line:  fprintf ( m_file, "%s\n", curCommand ) ;
I get in the file garbage instead of the string in curCommand.

When I compile the program using the line:  fprintf ( m_file, "%s\n", (char*)curCommand ) ;
I get the error below:

error C2440: 'type cast' : cannot convert from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *'

How can I print the data stored in the String argument ? note that in the debug winow I see that curCommand has the correct value.

Thanks.
0
Comment
Question by:chayahd99
2 Comments
 

Author Comment

by:chayahd99
ID: 11997048
After looking for 2 days, I found the solution: curCommand.c_str()
It was in http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20164790.html

I will ask for a refund.
0
 

Accepted Solution

by:
RomMod earned 0 total points
ID: 11998005
The question has been PAQ'd and the 30 points have been refunded.
RomMod
Community Support Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now