It seems like you are intending to read the numbers from the text file named "Lab3Test.txt". If so, there is no need to use the command line parameters (argc, argv) at all.
#include <iostream>
#include <fstream>
usingnamespace std;
int main()
{
ifstream mean("Lab3Test.txt");
if (!mean)
{
cout << "could not open input file\n";
return 1;
}
double total = 0;
double number;
int count = 0;
// testing if i get the numbers from my text file
while ( mean >> number )
{
cout << number << " ";
total += number;
count++;
if (count % 10 == 0)
cout << endl;
}
cout << endl;
// doing the average of the numbers
double avg = total/count;
cout << "The average is " << avg << endl;
}
how do i use c++ to open my text file with command line
First check that there are at least two parameters (count argc).
The first, argv[0] is the name of the current executing program.
The second, argv[1] is the first actual parameter entered on the command line. Use that as the file name.