my text is something like this
55<space>
The User Input Sentence;
i got the 55 out via the code below and assigned that to a int variable via atoi
std::string stringKey = userInput.substr(0, 2);
but how to get the rest of the string and assign it to a string variable ????the code below
this is the complete code (haven't finished it yet)
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;
//FUnction Prototypes
string encrypt(string, int);
string decrypt(string source, int key);
int main(int argc, char *argv[])
{
string source;
string userInput;
int key;
int choice;
cout << "To encode a message type 1, to decode a message type 2: ";
cin >> choice;
if (choice == 1)
{
cout << "Enter the message to encode: ";
cin >> userInput;
std::string stringKey = userInput.substr(0, 2);
key = atoi(stringKey.c_str());
std::string source = userInput.substr(3);
encrypt(source, key);
}
/*decrypt(source, key);
cout << "Source: ";
getline(cin, source);
cout << "Key: ";
cin >> key;
cout << "Encrypted: " << decrypt(source, key) << endl;*/
system("pause");
}
string encrypt(string source, int key)
{
string Crypted = source;
for (int Current = 0; Current < source.length(); Current++)
Crypted[Current] = ((Crypted[Current] + key) - 32) % 95 + 32;
return Crypted;
}
string decrypt(string source, int key)
{
string Crypted = source;
for (int Current = 0; Current < source.length(); Current++)
Crypted[Current] = ((Crypted[Current] - key) - 32 + 3 * 95) % 95 + 32;
return Crypted;
}