0
我不是要求我尋求幫助的代碼。是的,這是一個課程項目。從文件讀取並執行按位操作的C++程序
程序讀取包含這樣的.txt文件,
- NOT 10100110
- 和00111101
程序需要根據該操作者讀取操作和執行功能改變字節。然後輸出更改的字節。
我知道該怎麼做:
- 打開文件了。
- 從文件中讀取。
- 我可以將字節存儲在一個數組中。
我需要什麼幫助:
- 讀操作(AND,OR,NOT)
- 店的每一位內部數組(我可以存儲字節而不是位)
我的代碼:
#include <iostream>
#include <fstream>
#include <istream>
#include <cctype>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
const int SIZE = 8;
int numbers[SIZE]; // C array? to hold our words we read in
int bit;
std::cout << "Read from a file!" << std::endl;
std::ifstream fin("small.txt");
for (int i = 0; (fin >> bit) && (i < SIZE); ++i)
{
cout << "The number is: " << bit << endl;
numbers[i] = bit;
}
fin.close();
return 0;
}
這是什麼打印? – alestanis
您正在執行'fin >> bit',其中'bit'未初始化。 – 0x499602D2
@David:是的,是嗎? – Beta