473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

page 293 of C++ primer,4th edition

how to use c_str() ?

if I compile the following program, there are errors.

#include<iostream>
#include<fstream>

void main()
{
ofstream outfiloe(ofile.c_str());
}

Sep 18 '06 #1
6 1398
add

using namespace std;

--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

"asdf" <li*********@gmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
how to use c_str() ?

if I compile the following program, there are errors.

#include<iostream>
#include<fstream>

void main()
{
ofstream outfiloe(ofile.c_str());
}

Sep 18 '06 #2
asdf wrote:
how to use c_str() ?

if I compile the following program, there are errors.

#include<iostream>
#include<fstream>

void main()
main returns int. Always.
{
ofstream outfiloe(ofile.c_str());
What is ofile? Where did you define it? Without the definition, this
is an error.

ofstream resides in the std namespace, so you need to qualify it with
"std::".

Best regards,

Tom

}
Sep 18 '06 #3
"asdf" <li*********@gmail.comwrote:
how to use c_str() ?

if I compile the following program, there are errors.

#include<iostream>
#include<fstream>

void main()
{
ofstream outfiloe(ofile.c_str());
}
Moonlit wrote:
add

using namespace std;
Do you believe that adding that will fix the program?

Best regards,

Tom

Sep 18 '06 #4

"Moonlit" <news moonlit xs4all nlwrote in message
news:45**********************@news.xs4all.nl...

Please don't top-post. Place responses after (or interspersed with) what
you're responding to. [re-arragned]

>how to use c_str() ?
It's a member of std::string. Look it up.
>>
if I compile the following program, there are errors.

#include<iostream>
#include<fstream>

void main()
int main()
>{
ofstream outfiloe(ofile.c_str());
What's "ofile"?
>}
add

using namespace std;
Ron, you didn't say where to add that. But better, in such a simple case,
would be to add the std:: specifiers where needed, or to add using
statements for the specific std:: items that will be used.

But, there's more here wrong than just that.

What's "ofile"? It's not defined. I'm guessing it's supposed to be a
std::string, given the use of c_str(), but I don't see it declared as such
anywhere. And the <stringheader needs to be included if using strings.
Also, the string needs to get its content filled somehow, such as by using
std::cin.

If this was an attempt at reducing what you're posting, you cut out too
much. Read the FAQ, at http://www.parashift.com/c++-faq-lite/ (especially
section 5, reagarding how to post here for best results).

And if you're getting errors you don't understand, post the error message
(the text; error numbers mean nothing for people using other compilers), and
tell us which line of code generates the error.

Lastly, most of us probably don't have the book referred to in your subject
line. Make your subject lines more specific to the problem (such as "error
using c_str()" or "how do I use c_str()?"). In the body of your message,
you can refer to the book you're getting an example from (but don't expect
we'll all have that book).

-Howard
Sep 18 '06 #5
Moonlit wrote:
add
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.com/c++-faq-lite/how-to-post.html>
Sep 18 '06 #6
asdf wrote:
how to use c_str() ?

if I compile the following program, there are errors.

#include<iostream>
#include<fstream>

void main()
{
ofstream outfiloe(ofile.c_str());
}
In the future, post complete programs. Do that by copying the actual
code, not retyping. Also include the exact error messages.


Brian
Sep 18 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Charles L | last post by:
Does anyone know where I can find errata for Stan Lippman's 'C++ Primer 2nd Edition'? Charles Leng
1
by: Ciko | last post by:
I had a look at this book: "C Primer Plus, Fifth Edition Stephen Prata " and I found simply fantastic. My english is little but I had no problem to understand it. Was wondering if you...
3
by: huangshan | last post by:
hi all I read "C++ Primer, Fourth Edition" , but can't understand this sentence "By making the parameters const references, we allow types that do not allow copying." in "16.1. Template...
17
by: arnuld | last post by:
Exercise 4.28: Write a program to read the standard input and build a vector of ints from values that are read. Allocate an array of the same size as the vector and copy the elements from the...
2
by: W. Watson | last post by:
Is there a primer out there on these two items? I have the Python tutorial, but would like either a Tkinter tutorial/primer to supplement it, or a primer/tutorial that addresses both. Maybe there's...
2
by: xianwei | last post by:
First, typedef struct pair { Node *parent; Node *child; } Pair; static Pair SeekItem(cosnt Item *pI, const Tree *pTree) { Pair look;
1
by: Kveldulv | last post by:
Hi all, here is the code: http://pastebin.com/m6e74d36b I'm stuck at highfink constructor, last line before #endif. As parameters, I have reference to one parent class and int member of another...
1
by: mmdspam | last post by:
Hi, Can someone please tell me the answer to exercise 1.20 in C++ Primer 4th edition. I am stuck on this question. Thank you in advance
2
by: jerry | last post by:
can anyone tell me where can i get the keys to c++ primer 4th edition, pdf or chm type are both ok. thank you!
2
by: shezad.ps3 | last post by:
Hi, I need to make my c++ knowldge deeper as it is, I've got the third edition of the Lipman book but I have been told that the latest revision is a tremendous improvement from the one I've...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.