LinuxQuestions.org
Visit Jeremy's Blog.
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 03-15-2010, 06:49 PM   #1
azraelluz
LQ Newbie
 
Registered: Mar 2010
Posts: 1

Rep: Reputation: 0
how to read a txt file with C++ in linux and output it?


Hi guys
i'm really new to this stuff.
i have wrote a long piece of code above with the "main" which is calling openFile( &fout, filename )

filename contains the txt name in a form of "data.txt"
i wanna read the data from the file and output it into fout for later use.

the data in that file is a vector looking interger group.

i have the following code:

int openFile( ofstream * fout, const char * filename)
{

ifstream iFile(filename);
iFile >> &fout;
return 0;
}

when i make it, the following error messagge shows up:

315P3.cpp: In function ‘int openFile(std:fstream*, const char*)’:
315P3.cpp:52: error: no match for ‘operator>>’ in ‘iFile >> & fout’

how can i fix this problem?
thank you~!
 
Old 03-15-2010, 09:12 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by azraelluz View Post
Hi guys
i'm really new to this stuff.
i have wrote a long piece of code above with the "main" which is calling openFile( &fout, filename )

filename contains the txt name in a form of "data.txt"
i wanna read the data from the file and output it into fout for later use.

the data in that file is a vector looking interger group.

i have the following code:

int openFile( ofstream * fout, const char * filename)
{

ifstream iFile(filename);
iFile >> &fout;
return 0;
}

when i make it, the following error messagge shows up:

315P3.cpp: In function ‘int openFile(std:fstream*, const char*)’:
315P3.cpp:52: error: no match for ‘operator>>’ in ‘iFile >> & fout’

how can i fix this problem?
thank you~!
Before you go any further, do you know what >> and << operators mean in "C" and may mean in C++ ?

Also, regarding C++ and the two operators - do the operators have just one meaning or may have more than one meaning ?

Hint: have you ever heard of operator overloading in C++ ?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] how do I send output to both the screen and a txt file replica88 Linux - Newbie 2 01-29-2010 07:14 AM
Read a txt file in C xeon123 Programming 3 10-21-2007 12:14 PM
How to read HTML or TXT file and output the data? koolkicks311 Programming 1 04-21-2007 12:13 AM
How can read from file.txt C++ where can save this file(file.txt) to start reading sam_22 Programming 1 01-11-2007 06:11 PM
Read a line in a txt file with bash orgazmo Programming 5 05-03-2005 08:10 AM


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

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration