I tried my code below, and i am getting a output of 0. I added lines like cout << p; and cout << alpha to see if the values are getting stored into the variables. My output looks like this -18811398930we are in the loop0 Can anyone help me?? i am newbie to C++ so please take it easy on me. My input files looks like
23
.12
3
35
3
.
.
.
67
1
4
#include<iostream>
#include<fstream>
#include <stdio.h>
using namespace std;
int main()
{
int p;
int key;
double alpha;
int searchnum;
int numkeys;
int i;
ifstream inputfile;
inputfile.open("input.rtf", ios::in);
if (!inputfile)
{
cout <<"Unable to open file" ;
exit(1); //terminate
}
inputfile >> p; //first line of the input file
cout << p;
inputfile >> alpha; //second line of input file
cout << alpha;
inputfile >> numkeys; //third line of input file
for(i = 0; i <(numkeys+1); i++) //loop
{
inputfile >> key;
cout << "we are in the loop";
} //end loop
inputfile >> searchnum; //the last number used for a search
cout << searchnum;
inputfile.close();
} //close main