Reading floats and integers from files

In my programming class we just began using files and our first assignment deals with reading and integer from a file giving us the number of a triangle then reading three floating point numbers following the triangle number which represent the side lengths. I don't think I will have a problem figuring out ways in which to calculate and display the results but I cannot find a way in which to read integers and floating points into my program for use. The only option my professor told us about was inFile.get . The errors I'm getting seem to be telling me that I can only use this to read characters with this. I was looking up solutions to read floats and integers in from files but they all went way over my head. I want to understand what I am doing, not just copy things from the web. Thank you for any help. Here is my code so far.
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//----------------------------------------\\
// Purpose: To determine if data given by
// a file creates real triangles and if so
// to then calculate data sbout them. 
// Name: Will Beeler
// Date:October 28, 2009
//----------------------------------------\\

#include <iostream>
#include <iomanip>
#include <cctype>
#include <string>
#include <fstream>

using namespace std;

int main()

{

	string inFileTriangle, outFileTriangle;
	ifstream (inFile);
	ofstream (outFile);
	int triangleNumber;
	int sideLength;
	

	cout << "Enter the name of the input file: ";
	cin >> inFileTriangle;

	inFile.open(inFileTriangle.c_str());
	cout << "Enter the name of the output file: ";
	cin >> outFileTriangle;

	outFile.open(outFileTriangle.c_str());
	

    if( !inFile.good() )
    {
    cout << "Error opening input file" << endl;
    return 0;
    }//end if

    if(Output.fail( ))  
    {     
        cout << "Error opening output file"<<endl;  
        return 0;  
    }//end if


	cout << "Triangle No  SideA   SideB   SideC   Perimeter   Area\n";
	
	while(!inFile.eof())
	{
		//reads integer number which represents triangle number 
                inFile.get(triangleNumber);
		cout << "        " << triangleNumber << "   ";

		//reads the next three chracters( spaces included?) 
                //these represent the side lengths
		for(int i = 1; i < 4 ; i++)
		{
			inFile.get(sideLength);

		}//end for
	}// end while

        //Things to do:

	//reads the data for each triangle and finds and displays the perimeter and the area if it is a proper triangle

	//displays an error message if it is not a proper triangle

	//copies the data of the proper triangles and their perimeter and the  area to another file

	//finds maximum, minimum, and average values of the perimeters and the areas of the proper triangles 
	//(Please note that since we have no idea what the minimum and maximum values can be we need to initialize our variables by the limits of double variables.)

	//repeats this job for as many files as user requires

  return 0;
}



I only just glanced at your code, but one flaw I saw was how you're declaring infile and outfile.
They should be declared thus
1
2
ofstsream outfile;
ifstream infile;
Alright, no parenthesis. Thank you for that one. I think I found the solution for my problem. I guess I just was not aware that you could put the file name, the >> then variables to store the information in. Thanks for the correction above.
Topic archived. No new replies allowed.