(sorry i miss-typed dev c++ IDE)
hi,
i am a CS class right now, and my professor uses VS 2010. I on the other hand am cheap, and i opted to get dev c++ as a Integrated developing environment. I wrote this code for a project due tomorrow and it works fine for dev c++, but does not compile for VS. I need help figuring out what is wrong. Can anyone convert this so it can work for Visual studios?
thank you:

#include <iostream>
#include <fstream>
#include <iomanip>
#include<math.h>
using namespace std;
float array[100]; // 100 is maximum amount of numbers in the file
int size = 0;
float myMean(float meanArray[],int N);
float mySd(float sdArray[],int N);
// This function verifies to see whether the file exists or not
bool check_file(string filename)
{
    ifstream ListNumbers;
    ListNumbers.open(filename.c_str(),fstream::in);
    if (ListNumbers.good())
     {
        ListNumbers.close();
        return true ;
     }
    return false;
}
// This function reads the file and stores the number in an array
int read_file()
{
     ifstream filenumbers;
     string filename;
     int i=0;
     float numbers;
     cout << "Enter the name of the file: " << endl;
     cin >> filename;
     if (check_file(filename)==true)
     {
        filenumbers.open(filename.c_str(),fstream::in);
        while (!filenumbers.eof()) // Keeps reading the file until it ends
        {             
          filenumbers >> array[i];
          if (filenumbers)
           {
              size++; 
              i++;
           }
        }
        cout<<"The numbers in the input file are: "<<endl;
        for (int i=0;i < size ; i++)
          {
               cout << array[i] <<endl;
          }
        cout<<"Total number of elements in the input file are: "<<size<<endl;
        return 0;
     }
        filenumbers.close();
}

int main()
{
    read_file();
    float mean=myMean(array, size); //call to mean function.
    float standardDeviation=mySd(array,size); // call to standard deviation function.
    cout<<"The mean is: "<< mean<<endl; //mean output to console
    cout<<"The Standard Deviation is: "<<standardDeviation; //standard deviation output to console
     //output to file
    ofstream fout("DataStats.txt");
    if(!fout) 
              {
                 cout << "Cannot open output file.\n";
                 return 1;
              }
    fout << "The mean is: "<< mean<<endl; //mean output to file
    fout << "The Standard Deviation is: "<<standardDeviation<<endl; //standard deviation output to file
    fout.close();
    cout<<endl<<"Press any key to exit...";
    char c;
    cin>>c;
    return 0;
}



float myMean(float meanArray[],int N)
{
       
       float sum=0;
       for(int i=0;i<N;i++)
       {
            sum=sum+meanArray[i];   
       }        
       
       return (sum/N);     
             
  
} 

float mySd(float sdArray[],int N)
{
      
      float avg =myMean(sdArray, N);
      float sum=0;
      for(int i=0;i<N;i++)
              {
                  sum=sum+((sdArray[i]-avg)*(sdArray[i]-avg));   
              }        
      sum=sum/N;
      float stdev ;
      stdev= pow(sum,0.5);
      return (stdev);
            
}

Edited 6 Years Ago by cogitoergosum18: n/a

include <string>

>>stdev= pow(sum,0.5);

sum is a float, but 0.5 is a double. There are no overrides of pow() that take those parameters. change 0.5 to 0.5F to make it a float.

here are the error messsages:

error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(1144): could be 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(1146): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(1148): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(1150): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(155): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_istream<_Elem,_Traits> &(__cdecl *)(std::basic_istream<_Elem,_Traits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(161): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(168): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::ios_base &(__cdecl *)(std::ios_base &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(175): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::_Bool &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(194): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(short &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(228): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned short &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(247): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(int &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(273): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned int &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(291): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(309): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__w64 unsigned long &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(329): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__int64 &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(348): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned __int64 &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(367): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(float &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(386): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(double &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(404): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long double &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(422): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(void *&)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(441): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_streambuf<_Elem,_Traits> *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> while trying to match the argument list '(std::istream, std::string)'
1>c:\users\ee_217_99\documents\visual studio 2008\projects\filenamesumaverage\nikko.cpp(104) : error C2666: 'pow' : 6 overloads have similar conversions
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(575): could be 'long double pow(long double,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(573): or 'long double pow(long double,long double)'
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(527): or 'float pow(float,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(525): or 'float pow(float,float)'
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(489): or 'double pow(double,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(123): or 'double pow(double,double)'
1> while trying to match the argument list '(float, double)'

This article has been dead for over six months. Start a new discussion instead.