need help using <fstream> as a function

Aug 5, 2014 at 6:25am
i've made different functions and my text file does have words in it but nothing seems to print out. could someone check and see?

1
2
3
4
5
6
7
8
9
10
11
void display_score_text(ifstream& in_s, char x ) 
{
  	in_s.open("blackjack_score.txt");
	  in_s.get(x);
   	while (! in_s.eof())
	{
	      cout << x;
	      in_s.get(x);
    in_s.close();
	}
}	


its supposed to print out
your_Nalme: wins # / loss #
Last edited on Aug 5, 2014 at 7:07am
Aug 5, 2014 at 6:33am
my program runs and compiles but i can't seem print the words on the terminal. i was wondering if my function is written correctly
Aug 5, 2014 at 7:34am
You close the file after printing the first character.
Aug 7, 2014 at 5:16am
thank you, i've closed the loop in main
Aug 7, 2014 at 2:31pm
The parameters are redundant. They can be local var of display_score_text.

Also, it can be simplified as one while loop instead of many get and eof check:
1
2
while (in_s.get(x))
    cout << x;
Topic archived. No new replies allowed.