vector - How can i make this program look at more than the first character? -
#include <iostream> #include <string> #include <vector> using namespace std; int main() { const int setnum = 26; vector<char> normalv(setnum); vector<char> cipherv(setnum); string todec = ""; string beendec = ""; int = 0; normalv.at(i) = 'a'; cipherv.at(i) = '!'; ++i; normalv.at(i) = 'b'; cipherv.at(i) = '^'; ++i; normalv.at(i) = 'c'; cipherv.at(i) = '&'; ++i; normalv.at(i) = 'd'; cipherv.at(i) = '*'; ++i; normalv.at(i) = 'e'; cipherv.at(i) = '@'; ++i; normalv.at(i) = 'f'; cipherv.at(i) = '('; ++i; normalv.at(i) = 'g'; cipherv.at(i) = ')'; ++i; normalv.at(i) = 'h'; cipherv.at(i) = '-'; ++i; normalv.at(i) = 'i'; cipherv.at(i) = '#'; ++i; normalv.at(i) = 'j'; cipherv.at(i) = '_'; ++i; normalv.at(i) = 'k'; cipherv.at(i) = '='; ++i; normalv.at(i) = 'l'; cipherv.at(i) = '+'; ++i; normalv.at(i) = 'm'; cipherv.at(i) = '['; ++i; normalv.at(i) = 'n'; cipherv.at(i) = '{'; ++i; normalv.at(i) = 'o'; cipherv.at(i) = '$'; ++i; normalv.at(i) = 'p'; cipherv.at(i) = ']'; ++i; normalv.at(i) = 'q'; cipherv.at(i) = '}'; ++i; normalv.at(i) = 'r'; cipherv.at(i) = ';'; ++i; normalv.at(i) = 's'; cipherv.at(i) = ':'; ++i; normalv.at(i) = 't'; cipherv.at(i) = ','; ++i; normalv.at(i) = 'u'; cipherv.at(i) = '%'; ++i; normalv.at(i) = 'v'; cipherv.at(i) = '<'; ++i; normalv.at(i) = 'w'; cipherv.at(i) = '.'; ++i; normalv.at(i) = 'x'; cipherv.at(i) = '>'; ++i; normalv.at(i) = 'y'; cipherv.at(i) = '/'; ++i; normalv.at(i) = 'z'; cipherv.at(i) = '?'; ++i; // user inputs message { cout << "enter secret message: "; getline(cin, todec); } while (todec.length() == 0); beendec = todec; //decodes user's message (i = 0; < setnum; ++i){ if (todec.at(0) == cipherv.at(i)) { beendec.at(0) = normalv.at(i); } } //diplays decoded message cout << "decrypted message: " << beendec << endl; //command drive stay open cin.get(); cin.get(); return 0; }
any can appreciated. code supposed decode string example "!^&" should output "abc". right decodes first letter "a^&". feel because defined char , not string gives me error if change up. idea on how can modify work? in advance
i think loop should -:
//decodes user's message ( unsigned j = 0; j < todec.length(); j++ ) { ( = 0; < setnum; ++i ) { if ( todec.at( j ) == cipherv.at( ) ) { beendec.at( j ) = normalv.at( ); } } }
Comments
Post a Comment