LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to read a txt file with C++ in linux and output it? (https://www.linuxquestions.org/questions/programming-9/how-to-read-a-txt-file-with-c-in-linux-and-output-it-795616/)

azraelluz 03-15-2010 05:49 PM

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::ofstream*, const char*)’:
315P3.cpp:52: error: no match for ‘operator>>’ in ‘iFile >> & fout’

how can i fix this problem?
thank you~!

Sergei Steshenko 03-15-2010 08:12 PM

Quote:

Originally Posted by azraelluz (Post 3899552)
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::ofstream*, 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++ ?


All times are GMT -5. The time now is 10:04 PM.