LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-11-2003, 02:59 PM   #1
veilig
LQ Newbie
 
Registered: Oct 2003
Posts: 8

Rep: Reputation: 0
is my filename cause my problem?


alright, I'm using linux 9.0 and I'm using the C++ language,

what I need to do is grab input from a user and use that input to open a file.

the way I approached it was to grab the input from the user into a string. (string2)
I then concatenated two strings together to form one string. (string1+=string2)

and when I opened the file I used the command string1.c_str() for the filename.
Fin.open ( string1.c_str(), ios::in );
however, when I'm passing the file to another functions and try to read a line from the file in that function, I get the error message:
Node.cxx:24: invalid use of undefined type `struct std::basic_ifstream<char,
std::char_traits<char> >'
/usr/include/c++/3.2.2/iosfwd:86: declaration of `struct
std::basic_ifstream<char, std::char_traits<char> >'

the line that causes the error is:

Fin.getline ( Kdata, 5, '\n' );

where Fin is the file passed to the function, and Kdata is private data in a record. Kdata is a char array of size 4.
all I'm trying to do is just grab a small line, and put it into

I can't figure out why I'm getting this message, is there a better way to do this,.
 
Old 11-11-2003, 07:47 PM   #2
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
try passing the address of your fstream to your function.

ie.

Code:
int some_func (string, fstream &);

int main ()
{
    fstream in_stream;
    string fname;

   //get the fname blah blah blah
    some_func (fname, in_stream);
    return 0;
}

int some_func (string s, fstream &Fin)
{
    //do your open stuff.
    //return some error code blah blah blah
    return 0;
}
 
Old 04-22-2006, 10:32 AM   #3
nukkel
Member
 
Registered: Mar 2003
Location: Belgium
Distribution: Hardened gentoo
Posts: 323

Rep: Reputation: 30
Code:
#include <fstream>
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
long filename problem slack66 Linux - Newbie 5 11-05-2005 03:30 AM
long filename problem slack66 Slackware 1 11-03-2005 10:19 PM
change uploaded files from filename.avi to filename.avi.html like www.rapidshare.de latheesan Linux - Newbie 3 06-16-2005 04:33 AM
a fat filename problem mehlkelm Linux - General 8 05-03-2005 11:44 AM
short filename problem with solaris Gary_B9 Solaris / OpenSolaris 1 01-09-2003 01:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration