weird problem... (C++)
i am making a Caesar cipher encoder. heres the code: ////////////////////////////////////////////////////////////////////////////////////// #include <iostream> #include <string> #include <map> using namespace std; int main(){ map <string,int> charmap = {{"a",0},{"b",1},{"c",2},{"d",3},{"e",4},{"f",5},{"g",6},{"h",7},{"i",8},{"j",9},{"k",10},{"l",11},{"m",12},{"n",13},{"o",14},{"p",15},{"q",16},{"r",17},{"s",18},{"t",19},{"u",20},{"v",21},{"w",22},{"x",23},{"y",24},{"z",25}}; int rot; string text; string chars[27] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",}; cout << "enter a value (1 to 23): "; cin >> rot; cout << "\n" << "enter some text to encode: "; cin >> text; std::cin.ignore(); cout << "\noutput: "; int size = text.length(); /* debug start*/ cout << "size:" << size <<endl; cout << "text:" << text <<endl; /* debug end*/ for (int loop = 0; loop < size; loop++){ string tempchar = text.substr(loop); if (tempchar == "!") { cout << " "; }else { int temploc = charmap[tempchar]; temploc += rot; if(temploc>25){ temploc -= 26; } cout << chars[temploc]; } }; return 0; } ////////////////////////////////////////////////////////////////////////////////////// when i use it... this happens input: 1 hello output: bbbbp whats going on? also c++ only accepts input before white space when using "cin" for example if i inputted "hello there" it would only get the "hello" part. is there a way i can bypass it?