/* An example on the use of .getline() : file: 6ex6.cpp FALL 1998 ___________________________________ Jacob Y. Kazakia jyk0 October 21, 1998 Recitation Instructor: J.Y.Kazakia Recitation Section 01 ___________________________________ Purpose: This program reads from a file named 6ex6data.txt. It uses the function .getline to skip the first few lines of the file and then read the second line of the numerical data. The file 6ex6data.txt looks like this: _________________________________________________________________ THE DRAG FORCE CALCULATED FOR AN OBJECT OF FRONTAL AREA 2 m2 USING cd = 0.3 Speed Drag Force m/s miles/hour Newtons Pounds 0 0 0 0 5 11.1857 9.1875 2.06553 10 22.3714 36.75 8.26214 15 33.557 82.6875 18.5898 20 44.7427 147 33.0485 25 55.9284 229.688 51.6383 30 67.1141 330.75 74.3592 35 78.2998 450.188 101.211 40 89.4855 588 132.194 End of this table __________________________________________________________________ */ #include #include #include void main() { // declare the variables of the main function float speedMPS; float speedMPH; float dragNEWTONS; float dragPOUNDS; char a[80]; // array used to store the data read from the first 8 lines int m; ifstream table ( "6ex6data.txt" , ios:: in); for ( m = 0 ; m <= 7 ; m++ ) { table.getline( a, 80 ); } // read the data desired table >> speedMPS >> speedMPH >> dragNEWTONS >> dragPOUNDS; // output the data cout << " \n speed in meters per second " << speedMPS ; cout << " \n speed in miles per hour " << speedMPH ; cout << " \n drag force in Newtons " << dragNEWTONS ; cout << " \n drag force in pounds " << dragPOUNDS ; cout<<" \n\n enter e (exit) to terminate the program...."; char hold; cin>>hold; }