There is a simple issue with your code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main()
{
string line ;
std::fstream myfile("D:\\Task1.txt", std::ios_base::in);
getline( myfile, line ); // That's the problematic line!
//cout<<line.length();
while( getline( myfile, line ) ) // first line lost here
...
You read the first (and presumably only line) of the file and simply discard it, because you enter the while loop immediately afterwards.
Fix: Remove the line getline( myfile, line );
that precedes the while loop.
You should also check that the file actually exists (there may be a typo in the filename!):
std::fstream myfile("D:\\Task1.txt", std::ios_base::in);
if ( !myfile )
{
std::cerr << "File does not exist!\n";
return 1;
}
If you aren't planning to use the fstream for output as well, just replace
std::fstream myfile("D:\\Task1.txt", std::ios_base::in);
by
std::ifstream myfile("D:\\Task1.txt");