converting integers to "*"

I want to convert numbers from a file to "*" to keep them hidden.

so it would look like:

153634 = ******
123 = ***

I know I need some kind of loop but I'm not sure which kind. Can anyone give me some advice where to start?
Last edited on
If it is being displayed in an edit control you can use ES_PASSWORD for creating the control. Otherwise you'll need to intercept calls to write to the control and DIY.
I don't think you can do that. If your file has "******" saved in it, then you wont be able to ever get "153634" back.

Which isn't to say you can't "hide" the data by making it not human readable.

Easiest method I can think:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <fstream>
using namespace std;

int main(){
	ofstream outFile;
	int data = 1234;

	outFile.open("output.txt", ios::out | ios::binary);

	outFile.write((char*)&data, sizeof(data));


	outFile.close();
	cout << "\nDONE.  Hit ENTER to quit."; cin.get();
        return 0;
}


Now if you open the file in NotePad it will look like this: "Ӓ "

(It's actually less legible in NotePad).

You can still retrieve the data:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <fstream>
using namespace std;

int main(){
	ifstream inFile;
	int data
	inFile.open("output.txt", ios::in | ios::binary);

	inFile.read((char*)&data, sizeof(data));
	cout << data;

	inFile.close();
	cout << "\nDONE.  Hit ENTER to quit."; cin.get();
        return 0;
}


Or you could simply do some math on your number so that what gets written into the file isn't really what the number is. Then you can remember what math you did and reverse it when reading from the file.

Last edited on
Topic archived. No new replies allowed.