Fixing additional numbers added after reading in .txt file

So i created a program to read in from a .txt file with a few phrases in them, but when i get the computer to read them and print them to the screen the same 5 digit number is added and i cant figure out what is adding numbers. These are the numbers that are being repeated at the end (12142).

#include <iostream>
#include <vector>
#include <fstream>
#include <string>
using namespace std;





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int main()
{
	
	string line_;
	fstream file_("sqrt110.txt");
		if (file_.is_open())
		{
			while (getline(file_, line_))
			{
				cout << line_ << '/n' << endl;
			}
			file_.close();
		}
		else
			cout << "file is not open " << endl;
		cin.get();


	return 0;
}
Last edited on
What is '/n'? Do you mean '\n' for a new line?
Hello CodeStart99,


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.

You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.



It is also very helpful to include the input file with a program that requires an input file. As is I have no way to duplicate what you are describing because any input file I create may not match what you have.

Note: try to use the new line character (\n) over the "endl"s. "endl" is a function that takes time. The more you have the more time it takes to process. The C++11 standards allow the (\n) to work the same as "endl".

Andy
Topic archived. No new replies allowed.