OUTPUT:
Characters on line one: 3
Press any key to continue
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char input;
int count = 0;
ifstream infile;
infile.open("c:\\test.txt"); //premade text file
if (infile.fail())
{
cout << "Error loading file!" << endl;
}
infile >> input;
while (! infile.fail())
{
if (input != '\n')
{
count++;
infile >> input;
}
}
cout << "Characters on line one: " << count << endl;
return 0;
}
Attached is my text file i used, just paste it on your c drive.