Con risposta error C2784 with ifstream

  • lunedì 16 aprile 2012 20:08
     
      Contiene codice

    Hi, I'm getting this error error C2784 with some code I'm trying to compile to read a parameter file.  I created a test class with the same error is below.

    foo.h

    #pragma once
    
    #include <string>
    
    class Foo
    {
    public:
       Foo(void);
       ~Foo(void);
    
        static inline bool skipCommentsReadKey(std::ifstream& config, std::string& key);
    
    };
    
        inline bool Foo::skipCommentsReadKey(std::ifstream& config, std::string& key)
        {
            bool result = false;
    
            while (config >> key) {
                if (key[0] == '#') {
                    ignoreRestLn(config);
                    continue;
                }
                else {
                    result = true;
                    break;
                }
            }
            return result;
        }
    
    
    

    foo.cpp

    include "Foo.h"
    
    Foo::Foo(void)
    {
    }
    
    Foo::~Foo(void)
    {
    }
    

    The error I get is:

    1>------ Build started: Project: Error_C2784, Configuration: Debug Win32 ------
    1>Compiling...
    1>Foo.cpp
    1>c:\_dev\2012\cpptest_err2784\error_c2784\error_c2784\foo.h(19) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ifstream'
    1>        c:\program files (x86)\microsoft visual studio 8\vc\include\string(425) : see declaration of 'std::operator >>'

    Any help appreciated,

    Paul

Tutte le risposte

  • lunedì 16 aprile 2012 20:18
     
     Con risposta
    You also need to include fstream too.

    This is a signature

    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Do you want Visual Studio 11 Express to be freely installable on Windows 7 and able to write regular C++ applications? Please vote for this.

    • Contrassegnato come risposta Paul J__ lunedì 16 aprile 2012 20:28
    •  
  • lunedì 16 aprile 2012 20:29
     
     
    Thanks!

    Paul J.