Get my decrypt key from file

Nov 17, 2017 at 9:25pm
Hello.
I'm writing a program for encryption and decryption. I'm given a csv file which contains the key I need to encrypt and decrypt with. The file looks like that:
a,r
b,c
and so on. It means that a should be replaced with r,b replaces with c and etc.
I'm given the function encrypt(string text, fstream& dictionary)
I'm having a trouble separating the line a,r for example to text and key.
Nov 18, 2017 at 11:26am
I'm having a trouble separating the line a,r for example to text and key.

Assuming you have an ifstream or fstream opened for input, you could read from it like this. What you do with the values read from the file is up to you, this just prints them to the console.

1
2
3
4
5
6
7
8
9
10
    const char comma = ',';
        
    char text;
    char key;
    char spacer;
    
    while (  (infile >> text >> spacer >> key) && (spacer == comma)  )
    {
        cout << text << ' ' << key << '\n';
    }

Last edited on Nov 18, 2017 at 11:27am
Topic archived. No new replies allowed.