O
ophelia
hello, i am a beginner at C++ and i'm currently trying to write a small
application that reads a text file and display it out on screen. My
problem is that instead of reading the text file line by line, im
getting it as character by character, seperated by spaces! for
instance if the text file has the following data :
hello people!
my name is ophelia.
the output on screen that i'm getting is :
h e l l o p e o p l e !
m y n a m e i s o p h e l i a .
my code is as follows :
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
please..can anyone help me? is there something missing? thank you all
in advance. *muak*
application that reads a text file and display it out on screen. My
problem is that instead of reading the text file line by line, im
getting it as character by character, seperated by spaces! for
instance if the text file has the following data :
hello people!
my name is ophelia.
the output on screen that i'm getting is :
h e l l o p e o p l e !
m y n a m e i s o p h e l i a .
my code is as follows :
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
please..can anyone help me? is there something missing? thank you all
in advance. *muak*