void getKey (char m[][26], int size, char* filename){
ifstream fin;
char map[10][26];
fin.open("key.txt");
fin >> map;
fin.close();
}
the error Invalid operands to binary expression ('ifstream' (aka 'basic_ifstream<char>') and 'char (*)[26]')
occurred in the line fin >> map
i was wondering whats wrong in my programme please help thanksss
The insertion operator (>>) has no overload that matches an ifstream on one side and a char[10][26] on the other. You either need to supply that overload or perhaps read into map a line at a time. It depends on what exactly is in key.txt.
@tpb thank you so much for ur reply. In my key.txt file, it has 10 rows of characters, each row 26 characters. My task was to decrypt some messages according to the key.txt
did u mean that i should fin >> line by line, like fin >> s1....... until s10? thx
Something like this might do. Since map is maybe not a good name in C++ (which has a map type in the standard library) I changed it to key.
1 2 3 4 5
char key[10][26];
for (int i = 0; i < 10; i++) {
std::cin.getline(line, sizeof line);
strncpy(key[i], line, 26); // include <cstring> for this
}
Note that you can't treat the rows of key as strings since they are not zero-terminated. But as long as you are always accessing it by index that may be okay.