Output to command line format

Hi I am trying to read in from a file based on the users input of the file name. I am running into one problem. The text file that i have to test has a space after the first line which looks like this:
Here


Is

A

SAMPLE

TEXT

File that i will

use to show input.


the output is this:

Here

Is

A

SAMPLE

TEXT

File that i will

use to show input.

why does it get rid of one line after Here.

Here is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

class Text
{
	public:
		string name;
		string object;
		Text();
		void contents();
};

int main()
{
	Text txt1;
	txt1.contents();
	cin.ignore();
	return 0;
}

Text::Text()
{
	name = " ";
	object = " ";
};

void Text::contents()
{
	cout << "Please enter the name of the text file to be opened (Please include file extention): " << "\n";
	cin >> name;
	ifstream in(name); // Opens test4.txt for reading
	
	if (in == NULL) 
	 {
			 cout << "Error opening file";
			 cin.ignore();
	 }
	
	 else
	 {
		while(getline(in,object))
		{
			cout << object;
			cin.ignore();
		}
	}
};
Because getline ignores new line character (or other delimiter).
You may modify lines 45-46 with
1
2
			cout << object << endl;
			//cin.ignore(); 
Isn't there a way to change the default delimiter value?
Basically, there are two getline() functions:
1
2
istream& getline ( istream& is, string& str, char delim );
istream& getline ( istream& is, string& str );


The first one can use any delimiter.

http://www.cplusplus.com/reference/string/getline/
Topic archived. No new replies allowed.