My first question on this site, here goes:
I am working on a tutorial question and it asks me to write a program that outputs the product of some entered floating point numbers from the command line: This is to be done using streams.
Now in My tutorial book it suggests using the following code:
#include <iostream>
#include <cstdio>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <string>
#include <cstdlib>
#include <istream>
using namespace std;
int main( int argc, char* argv[] )
{
float data[20];
int i;
float sum;
for(i=1;i<argc-1;i++){
istream cinx(81,argv[i];
cinx>>data[i];
cout<<data[i];
sum=sum+data[i];
}
cout<<"\nsum = "<<sum;
}
So I have tried the above code and many different variations until my hair is falling out! – But to no avail as it does not compile, instead I get the error message along the lines of:
” no matching function for call to `std::basic_istream >::get(char**&, int)”
Any suggestions would be much appreciated.
istream constructor expects a streambuf. You probably want to use istringstream:
and
#include <sstream>in the beginning.Besides, you’re computing the sum, not the product.