?
Solved

fprintf error

Posted on 2004-09-07
2
Medium Priority
?
426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

770 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