473,324 Members | 2,257 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,324 software developers and data experts.

declaring a stream then defining it

Hi

can I declare an ofstream in a class declaration in .h file and define
it inside a method in the .cpp file? if so, what does the syntax of
defining it looks like.
I tried

....
ofstream out; // in .h file

and

myclass::myfun(){
....
string s = "some.file";
out(s.c_str()); //in .cpp file
....
on the line above, I get
error: no match for call to '(std::ofstream) (const char*)'

so that another method uses it

myclass::myotherfun(){
out << ...
thanks
Aug 23 '06 #1
1 1651
"Gary Wessle" <ph****@yahoo.comschrieb im Newsbeitrag
news:87************@yahoo.com...
Hi

can I declare an ofstream in a class declaration in .h file and define
it inside a method in the .cpp file? if so, what does the syntax of
defining it looks like.
I tried

...
ofstream out; // in .h file
This is a definition, not a declaration. A declaration would be

extern ofstream out;

but I suspect you want to define a stream variable (or member variable of
some class) and open it later.
and

myclass::myfun(){
...
string s = "some.file";
out(s.c_str()); //in .cpp file
That'd be a call of ofstream::operator()(char const*). If you want to open a
file on that stream, try

out.open(s.c_str());

HTH
Heinz

Aug 23 '06 #2

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

Similar topics

0
by: Terence Parker | last post by:
I am trying to connect an e-commerce system to a payment gateway (located in Hong Kong). The gateway takes values in the form of a simple form submit - however, the results (i.e. authorisation...
2
by: Sriram Chadalavada | last post by:
Hello everyone, I am a newbie to Python with experience in C programming. For my project, I am re-writing C routines as Python functions. I am currently using raw numerical values and was...
7
by: Bob Rock | last post by:
Hello, this may seem a strange question, but is there a way of being able to call methods of a class through an array of that class when not referencing a specific object in the array. In other...
3
by: Mac | last post by:
Is it legal to declare errno after you've included errno.h? For example: #include<errno.h> .... int main (void) {
20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the...
11
by: bob | last post by:
Hi, given a vector of vectors of strings thus; typedef std::vector<std::string> product; typedef std::vector<product> product_matrix; whats the fastest, most efficient means of streaming...
8
by: T Driver | last post by:
Anyone have any idea how I can do the following? I have a connection to an XML file on a site I do not control, getting a string representation of the xml data that I can then feed to my...
5
by: =?Utf-8?B?RWl0YW4=?= | last post by:
Hello, I am declaring an element like this: public static List<myListElementmyList = new List<myListElement>(); I would like to declare an array of this myList. How would I modify the...
5
by: newbarker | last post by:
Hello all, #include <sstream> #include <iostream> int main() { std::istringstream iss("6.5e"); double size; char fit;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.