I have the code:
#include <fstream> #include <iostream> using namespace std; int main() { const int numArr = 100; char text[numArr]; ifstream file("text.txt"); file.getline(text, numArr); file.close(); for (int i = 0; i < numArr; i++) cout << text[i]; system("pause"); return 0; } The text.txt document says:
Один, два, три Why, when I run the program, do I get extra characters in the console (in this case, the letter Mm)?
Один, два, три ММММММММММММММММММММММММММММММММММММММММММММММММММММММММММММММММММММММДля продолжения нажмите любую клавишу...
memset(text, '%', numArr);before readingmemset(text, '%', numArr);, the buffer will be filled with the%character. But it is still not clear to me why you print the entire buffer (100 characters) when only 14 characters were read from the file. Just for the sake of experiment? - AnT