samedi 31 octobre 2015

Code to print out number of lines and integer values

i created a data file called program.txt I need to create a code that prints out number of lines and integer values from that program.txt Heres the text I made

         1

        35
        45
        87

         9 

       100

the program.text has these values in it

   #include <iostream>
    #include <string>
   #include <fstream>




   using namespace std;

  int main()
  {
string calc;
int test;
int cool;
int book;
ifstream myfile;
ifstream outof;
myfile.open ("program.txt");
outof.open("program.txt");
if (myfile.fail())
{
    cerr<<"Error Opening file"<<endl;








}

if(outof.fail ())
{
    cerr<<"Error Opening file"<<endl;


}
while (!myfile.eof ())
{
    getline(myfile,calc);

}
cout <<calc<<endl;
while (!outof.eof ())
{
    outof<<test;// Problem Here<-- Its saying Unspecified operator

    cool++;
}
cout<<cool<<endl;
myfile.close();
outof.close();
        }

also after cerr I tried exit (1) and it said exit was not defined. I am new to this any help would be greatly appreciated Thanks This is C++ btw And This is my first Post YAY!

Aucun commentaire:

Enregistrer un commentaire