Hi,

I'm trying to write this program where there is:
(1) a greeting
(2) make columns
(3) have a stored text file input into the program automatically
The file is like so:
NOT 11010011
AND 10010010
etc.
(4) read the first word and then output it
(5) read the first binary number pattern and output it


Thusfar I have made (1) and (2) and (3), but I'm having difficulties with (4). I tried searching online, but all I come across is getline in bit format.

would I do

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

int main ()
{
char CONVERT [7];
string fileNAME;

greeting ();

cout << setw(10) << "COMMAND" << "Operand #1" << "Operand #2" << "Shift" << "Result" << endl;
cout << setfill('-') << setw(50) << "-" << endl;

ifstream inFILE;
cout << "Please enter file name:";
cin >> fileName;
inFile.open (fileName.c_str()):

[B]getline (CONVERT,7)[/B]
return 0;
}

Recommended Answers

All 4 Replies

Try something like

ifstream input;
input.open ("data.txt", fstream::in | fstream::out | fstream::app);
 int i = 0;
 int a[numberofwords];
 while(!input.eof())
{
input >> variables[i];
i++;
}
input.close();
}

OK, this is something that should work. Edit it to fit your need:
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main ()
{
string CONVERT [7];
string fileNAME;
string fileName;
cout << "HI"; //greeting();

cout << setw(10) << "COMMAND" << "Operand #1" << "Operand #2" << "Shift" << "Result" << endl;
cout << setfill('-') << setw(50) << "-" << endl;

ifstream inFILE;
cout << "Please enter file name:";
cin >> fileName;
inFILE.open(fileName.c_str());
int i = 0;
while(!inFILE.eof())
{
inFILE >> CONVERT;
i++;
}
inFILE.close();

//getline (CONVERT,7);
return 0;
}

OK, this is something that should work. Edit it to fit your need:

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

int main ()
{
string CONVERT [7];
string fileNAME;
string fileName;
cout << "HI"; //greeting();

cout << setw(10) << "COMMAND" << "Operand #1" << "Operand #2" << "Shift" << "Result" << endl;
cout << setfill('-') << setw(50) << "-" << endl;

ifstream inFILE;
cout << "Please enter file name:";
cin >> fileName;
inFILE.open(fileName.c_str());
int i = 0;
while(!inFILE.eof())
{
inFILE >> CONVERT[i];
i++;
}
inFILE.close();

//getline (CONVERT,7);
return 0;
}

thank you very much!

btw, i do not get what the .eof is. Could you please explain?

however, there is a "term does not evaluate to a function taking 1 arguements" error on line 24.

I was also going to put a
"Do /*line 17
{ /*line 18
} /*line28

It makes sense to run the loop but it says "syntax error : 'return'

I do not know what I am doing wrong.

Thank you for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.