c++
By: jazy84 | Date: Nov 22 2007 01:09 | Format: C++ | Expires: never | Size: 1018 B | Hits: 1349
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- string dectobin(int num,int base,int byte);
- //string convert(int bits);
- int main() {
- ifstream inFile;
- ofstream outFile;
- //input file stream
- //output file stream
- string inFileName,outFileName;
- inFileName = "input6.txt";
- outFileName = "output6.txt";
- inFile.open(inFileName.c_str());
- outFile.open(outFileName.c_str());
- int decimalNumber,bit;
- int const base = 2;
- /* checking if file input and is valid. Doesn't matter about outFile, since it will be created */
- if (!inFile) {
- cerr<<"Can't open Input file '"<<inFileName<<"'n";
- return 1;
- }
- inFile >> bit;
- cout<<"Bit: "<<bit<<endl;
- inFile >> decimalNumber;
- while(!inFile.eof()) {
- cout<<"Dec: "<<decimalNumber<<" = " <<dectobin(decimalNumber, base, bit) <<endl;
- outFile<<"Decimal: "<<decimalNumber<<" = "<<dectobin(decimalNumber, base, bit)<<endl;
- inFile >> decimalNumber;
- }
Latest pastes
1 days ago
1 days ago
2 days ago
3 days ago
5 days ago