473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Error: invalid operands of types `double' and `double' to binary `operator>>'

Expand|Select|Wrap|Line Numbers
  1. #include<cstdlib>
  2. #include<iostream>
  3. #include<iomanip>
  4. #include<vector>
  5.    #include<fstream>
  6. using namespace std;
  7.  
  8. double sum(vector<double> x)
  9.  {
  10.     double total = 0.0; 
  11.     for (int i=0; i<x.size(); i++) {
  12.         total = total + x[i];  
  13.     }
  14.     return total;
  15. }
  16.  
  17.  
  18.  
  19. int main()
  20. { vector<double> numbers;
  21.     double number;
  22.  int n;
  23.     ifstream in("data.txt");
  24.     while(in>>number)
  25.     {numbers.push_back(number);      }
  26.      for(int i=0;i<numbers.size();i++) 
  27. n= numbers.size();    
  28.     double k=sum(numbers);
  29. double y;
  30.   y=k/n;
  31.  
  32.      cout<<"mean of the values is:"<<" "<<y<<endl;
  33.  
  34.  for(int i=0;i<numbers.size();i++) 
  35. { double m= ((numbers[i]-y)*(numbers[i]-y));
  36.      vector<double> digits;
  37.      double digit;
  38.      while(m>>digit)
  39.      {digits.push_back(digit);}
  40.      double f=sum(digits);
  41.      double w=f/n;  
  42. cout<<"variance of the values is:"<<w<<endl;}
  43.  
hmmm,trying to calculate variance from values in vectors.but keep getting error saying invalid operands of types `double' and `double' to binary `operator>>' what does tt mean n what shld i do?
Sep 17 '07 #1
2 29631
sicarie
4,677 Expert Mod 4TB
The line 38 above, 'while (m>>digit)' . You declare m as a double, and then try to use it as you would a filehandle and read data in from it. So your types don't match, which is giving you that error.
Sep 17 '07 #2
sicarie
4,677 Expert Mod 4TB
Also, I've changed the thread title, please have a look at the Posting Guidelines, as we ask that when you post you do things like use a good thread title, code tags, etc... Thanks!
Sep 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Peter Ammon | last post by:
As we know, due to C++'s "longest match" rule, the >> token causes headaches when working with nested templates, e.g. vector<vector<int>> will not parse correctly without inserting a space...
4
by: Dan | last post by:
Hi, I would just like to know if the istream operator takes only one parammeter(object) at a time (like z) ? istream operator>>(istream& in, Shape &z) Cause I keep getting error concerning the...
0
by: ma740988 | last post by:
Consider #include <iostream> #include <string> #include <map> using namespace std; struct dstream // data_stream class {
0
by: Frank King | last post by:
Hi, I am using CArray and quick sort funciton to sort an array of double type of data points. I found an article in MSDN HOWTO: Quick Sorting Using MFC CArray-Derived Classes ID: Q216858 ...
5
by: John Nagle | last post by:
This, which is from a real web site, went into BeautifulSoup: <param name="movie" value="/images/offersBanners/sw04.swf?binfot=We offer fantastic rates for selected weeks or days!!&blinkt=Click...
3
by: Demoris | last post by:
I have a class that I believe should work. I've compared it to previous programs I've written, compared it to examples from my professor, to examples in my textbook, but can't see why I get the...
2
by: Colonel | last post by:
It seems that the problems have something to do with the overloading of istream operator ">>", but I just can't find the exact problem. // the declaration friend std::istream &...
1
by: Terry Archer | last post by:
Error 1 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) #include <iostream> #include <fstream> #include...
3
by: Brett Turner | last post by:
I am writing a client chat program, however every time I try to compile it, I get the same errors over and over... IntelliSense: no operator ">>" matches these operands WSAData wsaData;...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.