invalid operands to binary expression

Hi

I wrote this code

#include <iostream>
#include <vector>

using namespace std;

vector <double> somme(vector <double>, int);

vector <double> somme(vector <double> tableau[], int taille)
{
vector <double> somme(0);
int i = 0;
while (i<taille)
{
somme = somme + tableau[i];
i++;
}
return somme;
}

int main()
{

vector <double> somme_total;
double point;
vector <double> point1(0);

for (int i(0); i < 5; i++)
{
cout << "Donner point eleve 1";
cin >> point;
point1.push_back(point);
}
int taille = point1.size();
somme_total = somme(point1, taille);
cout << "Eleve 1 a :" << somme_total << endl;

}

But i get this response :

test2.cpp:14:17: error: invalid operands to binary expression ('vector<double>'
and 'vector<double>')
somme = somme + tableau[i];

test2.cpp:35:23: error: invalid operands to binary expression
('basic_ostream<char, std::__1::char_traits<char> >' and 'vector<double>')
cout << "Eleve 1 a :" << somme_total << endl;

I don't get the idea....!!
What do you mean vector + vector means? Should it add respective values together? Should it push values of second vector after first? As those questions cannot be answered undoubtebly, there is no + operator for vectors. You need to do what you want manually.

What does it means to output vector? Should every value be output on the same line? Separate lines? Should values be separated by comma? Semicolon? Tab? Exclamation mark? For those reasons, you need to output vector yourself as you need.
Topic archived. No new replies allowed.