Hardcoding text file

Hey again everyone!

So I'm trying to "hardcode" a file xfile.txt into my program, I;m supposed to be able to access the file and pull info per line. Will What I'm doing work? I havent tried running the prgram yet since I'm barely starting!

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
 #include <iostream>

using namespace std;

int main()
{
	double MeanExamScore; //must be a real number with 2 digits of precision
	int SumOfAllScores; //sum of all scores
	int NumScores; //number of scores

	 const char *filename = "C:\Users\Luciana\Documents\Florida State University\COP 3014 Fall 2013\fifthprogram\fifthprogram\xfile.txt";

    printf("Filename is: %s\n", filename);

	MeanExamScore = SumOfAllScores / NumScores; //this calculates the Mean Exam Score

	//the following block will output the histogram
	cout << "Frequency\n" << 
	cout << "---------\n" <<
	cout << '\n' <<
	cout << "Score" << "        " << "Obtained By" << "        " << "    5     10     15     20     25" << endl;
	cout << "-----" << "        " << "-----------" << "        " << "----|------|------|------|------|" << endl;
	cout << "0...5" << "        " << endl;
	cout << "6...10" << "        " << endl;
	cout << "11...15" << "        " <<endl;
	cout << "16...20" << "        " << endl;
	cout << "21...25" << "        " << endl;
	cout << "26...30" << "        " << endl;



		return 0;
}
Based on what I see, you aren't doing anything with the directory that the txt file is in. I don't see any opening of the file and obtaining information from it.
How would I be able to open the file and use it line by line?
Will this work in opening my file and be able to use it line by line?

1
2
3
	string input;

	fstream dataFile ("xfile.txt", ios::in);


I'm thinking of using "getline" thereafter.
Last edited on
Topic archived. No new replies allowed.