read files to unsigned int
How to store a file to unsigned int
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
//Main.cpp
#include <iostream>
#include <fstream>
using namespace std;
unsigned int key[4];
int main(){
ifstream file("key.txt");
store(file);
return 0;
}
|
i having this data in my key.txt
1 2 3 4
|
0xFDA5
0xD54E
0xFC00
0xB55A
|
I Created this function
1 2 3 4 5 6 7 8 9 10 11 12
|
void store(ifstream &file){
int i = 0;
if(!file)
cout << "Couldn't open file " << endl;
while(!file.eof()){
file >> key[i];
i++;
}
}
|
it just looping nonstop. what should i change in order to store correct data to
key
The values you are reading in aren't unsigned integers. Use a hex modifier to convert when you pass in:
ex. file >> hex >> key[i];
so if want to output back the data with
1 2 3 4
|
0xFDA5
0xD54E
0xFC00
0xB55A
|
because when i output the data what i get is all numbers
when output should i covert to decimal or binary?
Topic archived. No new replies allowed.