Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Strange errors related to getline()...

Strange errors related to getline()...

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CoffeeAddict19
    wrote on last edited by
    #1

    Basically what I'm trying to do is open up a file, check to see if everything is ok, and then get a line from the file and pop up a box with the text from the getline(). Then I got all these errors upon compiling. The line which the errors are pointing to is marked with a smilie. I don't really know what to do with them so I'd appreciate any help. The code:

    bool CRatiosNewSearchDialog::LoadExpressionsFile(CString Path)
    {
    	bool Success = true;
    	CString FirstLineText = "";
    	
    	ifstream expressionFInput(Path); //open up file, should automatically close too
    	if(expressionFInput.fail()) //see if it's missing or not
    	{
    		MessageBox("Could not load expressions file: " + (CString)Path, "Error", MB_ICONWARNING);
    		Success = false;
    	}
    	else if(EOF == expressionFInput.peek()) //check if the file is empty
    	{
    		MessageBox("Expressions file is empty: " + (CString)Path, "Error", MB_ICONWARNING);
    		Success = false;
    	}
    	else //everything is cool if we got this far
    	{
    		:^)getline(expressionFInput, FirstLineText, '\n');
    		MessageBox(FirstLineText, "First Line", MB_OK);
    	}
    
    	return Success;
    }
    

    These are the errors: \Work\Copy of Ratios_2006\Ratios\ratios_searchdialogs.cpp(58): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : expects 2 arguments - 3 provided \Work\Copy of Ratios_2006\Ratios\ratios_searchdialogs.cpp(58): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ifstream' \Work\Copy of Ratios_2006\Ratios\ratios_searchdialogs.cpp(58): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Ax> &' from 'CString' I'd appreciate any help. -John

    N 1 Reply Last reply
    0
    • C CoffeeAddict19

      Basically what I'm trying to do is open up a file, check to see if everything is ok, and then get a line from the file and pop up a box with the text from the getline(). Then I got all these errors upon compiling. The line which the errors are pointing to is marked with a smilie. I don't really know what to do with them so I'd appreciate any help. The code:

      bool CRatiosNewSearchDialog::LoadExpressionsFile(CString Path)
      {
      	bool Success = true;
      	CString FirstLineText = "";
      	
      	ifstream expressionFInput(Path); //open up file, should automatically close too
      	if(expressionFInput.fail()) //see if it's missing or not
      	{
      		MessageBox("Could not load expressions file: " + (CString)Path, "Error", MB_ICONWARNING);
      		Success = false;
      	}
      	else if(EOF == expressionFInput.peek()) //check if the file is empty
      	{
      		MessageBox("Expressions file is empty: " + (CString)Path, "Error", MB_ICONWARNING);
      		Success = false;
      	}
      	else //everything is cool if we got this far
      	{
      		:^)getline(expressionFInput, FirstLineText, '\n');
      		MessageBox(FirstLineText, "First Line", MB_OK);
      	}
      
      	return Success;
      }
      

      These are the errors: \Work\Copy of Ratios_2006\Ratios\ratios_searchdialogs.cpp(58): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : expects 2 arguments - 3 provided \Work\Copy of Ratios_2006\Ratios\ratios_searchdialogs.cpp(58): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ifstream' \Work\Copy of Ratios_2006\Ratios\ratios_searchdialogs.cpp(58): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Ax> &' from 'CString' I'd appreciate any help. -John

      N Offline
      N Offline
      Newbie00
      wrote on last edited by
      #2

      CoffeeAddict19 wrote:

      expects 2 arguments - 3 provided

      This is the answer. Look at the first error message.

      C 1 Reply Last reply
      0
      • N Newbie00

        CoffeeAddict19 wrote:

        expects 2 arguments - 3 provided

        This is the answer. Look at the first error message.

        C Offline
        C Offline
        CoffeeAddict19
        wrote on last edited by
        #3

        getline(expressionFInput, FirstLineText); same error. :/ It doesn't care whether I have 3 arguments or two. Go figure.

        N 1 Reply Last reply
        0
        • C CoffeeAddict19

          getline(expressionFInput, FirstLineText); same error. :/ It doesn't care whether I have 3 arguments or two. Go figure.

          N Offline
          N Offline
          Newbie00
          wrote on last edited by
          #4

          You've provided 2 arguments. Does the compiler say that you have provided 3??? :O:O Strange thing. Have you rebuilt the project or just proper cpp?

          N C 2 Replies Last reply
          0
          • N Newbie00

            You've provided 2 arguments. Does the compiler say that you have provided 3??? :O:O Strange thing. Have you rebuilt the project or just proper cpp?

            N Offline
            N Offline
            Newbie00
            wrote on last edited by
            #5

            Anyway if the error occurs after your change it means tha you have used wrong arguments check 2 another errors from your first post. Try to use istream instead of ifstream and string instead of CString

            C 1 Reply Last reply
            0
            • N Newbie00

              You've provided 2 arguments. Does the compiler say that you have provided 3??? :O:O Strange thing. Have you rebuilt the project or just proper cpp?

              C Offline
              C Offline
              CoffeeAddict19
              wrote on last edited by
              #6

              Yes. I rebuilt it. :) I hate Microsoft. e:\Work\Ratios\ratios_searchdialogs.cpp(61): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : expects 3 arguments - 2 provided

              1 Reply Last reply
              0
              • N Newbie00

                Anyway if the error occurs after your change it means tha you have used wrong arguments check 2 another errors from your first post. Try to use istream instead of ifstream and string instead of CString

                C Offline
                C Offline
                CoffeeAddict19
                wrote on last edited by
                #7

                I gave in and did it with a string...works fine. Thanks. Still annoys me the though. Has anyone written a defenitive guide on how all of these character and string formats work together? Has anyone done a performance analysis on the different types of strings and their functions to see what works fastest in what appication? Seems like someone could write a book on it.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups