Reading data from a file questions

Hello. I'm trying to read the data from C:\Random.txt
I've included the fstream but the compiler gets hung up at the inputFile.open line. I read in my book to use two backslashes. I tried to locate the Random.txt file in a basic location so the location address wouldn't be too long or complicated.

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
50
 /*CSC 134 80 Module 5 Week 2 
Peer Programming Assignment
Josh Krynock 3/27/16
This program will read a list of numbers from Random.txt file
and then calculate and display the following iformation:
1- The count of numbers in the file. 
2- The sum of all the numbers in the file (a running total)
3- The average of all the numbers in the file. 
*/

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

int main()
{
	//statement for reading a file
	
	ifstream inputFile;	
	//Open the file
	inputFile.open(c:\\Random.txt)
	
	//Variables 
	int 	numCount = 0;
	double 	aveNumbers, number, numTotal = 0;
	
	
	if (inputFile) //To test file open errors.
	{
		cout << "This program reads a list of numbers from a file\n";
		cout << "and the displays the number of numbers in the file,\n";
		cout << "the sum and the average of all the numbers in the file.\n";
		cout << "Reading file...\n\n";
		
		while (inputFile >> number)
		{
			cout << number << endl;
			numCount++;
			numTotal += number;
		}
		aveNumbers = (numTotal / numCount);
		cout << "Sum of numbers: " << numTotal << endl;
		cout << "Average of numbers: " << aveNumbers << endl;
		
	}
	else 
		cout << "File load error.";
	return 0;
}
You need double-quotes around strings and constant character arrays.
Thank you koothkeeper.
Topic archived. No new replies allowed.