The problem is the following, you need to read a few lines from the file and output. Starting from the second, numbering. To do this, made the counter and check it. But that's not the point. getline() truncates the first character in the lines, starting with the second. I can not understand what the problem is.
Example: An input file contains:
First Second Third Program text: #include "stdafx.h" #include // enable the input-output functions #include // enable the read-write functions in the #include file
using namespace std; // объявляем пространство имен void Func(const char *filename) { int counter = 0; char input; string line; ifstream a_1(filename, ios::in); if (a_1.is_open()) { while (a_1 >> input) { getline(a_1, line); if (counter == 0) { cout << line << "\n"; } else { cout << counter << " " << line << "\n"; } counter += 1; } } } int main() { Func("data.txt"); return 0; }