Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code that will accept input from file at time of a.out?

Status
Not open for further replies.

rego

Programmer
Apr 23, 2001
2
US
Hi:

I am writing code that will compute the median of a set of numbers (or grades) . I would like to know how I can make this program due two special things.

First, I would like for the code to accept a given amount of numbers defined by the amount the user would like to input.

Then I would like for this code to accept these numbers from a database that is entered like this.

>a.out <grades.cpp

I don't think that its possible to do the first part if I plan to use the second part. This is okay because I would rather use the second part.

Thanks in advance for any ideas you might have
rego

 
&quot; First, I would like for the code to accept a given amount of numbers defined by the amount the user would like to input.
&quot;
Sorta like this?
int main(char *filename = NULL)
{
if(filename)
{
ifstream fin;
fin.open(filename);
vector<float> grades;
while( !fin.eof() )
{
float temp;
fin >> temp;
grades.pushback(temp);
}
}
else
{
cout<< &quot;Insert grades, seprated by spaces. Press Enter to stop.&quot;;
int count = 0;
vector<float> grades;
float grade;
while(cin >> grade)
{
grades.push_back(grade);
}
get();
}
//Do your math.
return 0;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top