Solved

fprintf error

Posted on 2004-09-07
2
419 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

757 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

23 Experts available now in Live!

Get 1:1 Help Now