Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

fprintf error

Posted on 2004-09-07
2
Medium Priority
?
427 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

609 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