Logo 
Search:

C++ Programming Forum

Ask Question   UnAnswered
Home » Forum » C++ Programming       RSS Feeds

to read .txt file

  Asked By: Muneeb    Date: Sep 06    Category: C++ Programming    Views: 1228
  






Whats the wrong with this code ????



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

class mem
{
public:
static const int position=0;
static const int size = 65536;
unsigned char *m;
// m= new unsigned char[size];
void read()
{
ifstream fin("p1.txt"); //opening an input stream for file test.txt
/*checking whether file could be opened or not. If file does not exist or don't have read permissions, file
stream could not be opened.*/
if(fin.is_open()&&position<=15)
{
//file opened successfully so we are here
cout << "File Opened successfully!!!. Reading data from file into array" << endl;
//this loop run until end of file (eof) does not occur
while(!fin.eof() && position < size)
{
fin.get(m[position]); //reading one character from file to array
position++;
}
m[position-1] = '\0'; //placing character array terminating character

cout << "Displaying Array..." << endl << endl;
//this loop display all the charaters in array till \0
for(int i = 0; m[i] != '\0'; i++)
{
m[i]=m[i]+m[i+1];
cout << "R"<<i<<"="<<m[i]<<endl;
}
}
else //file could not be opened
{
cout << "File could not be opened." << endl;
}

}

};


class ALU:public mem
{
public:
void add()
{
int a=m[0];
int b=m[1];
a=a+b;
m[0]=a;
}
void sub()
{
int a=m[0];
int b=m[1];
a=a-b;
m[0]=a;
}
void mul()
{
int a=m[0];
int b=m[1];
a=a*b;
m[0]=a;
}

};





class reg: public ALU
{
public:
int bit_no;
//read();
//add();
void print()
{
for (int i=0; i<=15 ;i++)
{
m[i]=i;
cout<<"r"<<i<<"="<<m[i]<<endl;
}
}
};



int main()
{
reg r;
r.read();
r.add();
r.print();
//system("pause");
return 0;
}


whats the with this code?????

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on to read .txt file Or get search suggestion and latest updates.




Tagged: