I'm trying to read input from an array into a string, but it's not working so well. Here's my code.
std::string str1; //for(int i = 0; grid[0][i].letter !=0; i++) char ch1 = grid[0][0].letter; char ch2 = grid[0][1].letter; char ch3 = grid[0][2].letter; char ch4 = grid[0][3].letter; char ch5 = grid[0][4].letter; char ch6 = grid[0][5].letter; cout << ch1 << ch2 << ch3 << ch4 << ch5 << ch6; str1 += ch1 + ch2 + ch3 + ch4 + ch5 + ch6; cout << str1; Earlier, I had set the grid[0][x] to be equal to the chars 'e' 'g' 'g' 'c' 'a' 't', respectively. When I print all the ch chars next to each other, it displays "eggcat", as it should. However, for some reason, when I try to print out str1, which should also display "eggcat", it instead only gives me the letter 'k'. I've been trying for a while to fix this, but I haven't been able to at all. Does anyone know what the problem might be? I'm only #including iostream, iterator, and algorithm, so if I'm just forgetting to #include something, please let me know!