Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8641555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:33:23+00:00 2026-06-12T11:33:23+00:00

I am trying to take user input directly from console using getline into a

  • 0

I am trying to take user input directly from console using getline into a C++ string object. I am however failing to do so as the compiler gives me the following error.

main.cpp: In function ‘int main(int, char**)’:
main.cpp:52:28: error: no matching function for call to ‘std::basic_ifstream<char>::getline(std::ifstream&, std::string&)’
main.cpp:52:28: note: candidates are:
/usr/include/c++/4.6/istream:599:5: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::getline(std::basic_istream<_CharT, _Traits>::char_type*, std::streamsize, std::basic_istream<_CharT, _Traits>::char_type) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_istream<_CharT, _Traits>::char_type = char, std::streamsize = int]
/usr/include/c++/4.6/istream:599:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/4.6/istream:408:7: note: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::getline(std::basic_istream<_CharT, _Traits>::char_type*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>, std::basic_istream<_CharT, _Traits>::char_type = char, std::streamsize = int]
/usr/include/c++/4.6/istream:408:7: note:   no known conversion for argument 2 from ‘std::string {aka std::basic_string<char>}’ to ‘int’

Here is the source code:

#include <iostream>
 #include <fstream>
 #include <cmath>
 #include <cstdlib>
 #include <cstring>
 #include <string>
 #include <map>
 #include <set>
 #include <algorithm>
 #include <cstdio>

 #define MAX_LIN 1024

 using namespace std;

 typedef set<int> si;
int main(int argc, char** argv)
 {   
     string line1;
     string line2;

     map <string , si > iMap;

     if (argc != 3) { 
         fprintf(stderr,"Usage: a.out <file1> <file2>\n");
     }

     ifstream f1,f2;

     f1.open(argv[1],ifstream::in);
     f2.open(argv[2],ifstream::in);

     while(!f1.eof()) {
         getline(f1,line1);
         mParse(line1);
     }   

     while(!f2.eof()) {
         f2.getline(f2,line2);
         mParse(line2);
     }   

     f1.close();
     f2.close();


     return 0;
 }   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:33:24+00:00Added an answer on June 12, 2026 at 11:33 am

    This is the cause:

    f2.getline(f2,line2);
    

    should be:

    getline(f2,line2);
    

    There is a std::ifstream::getline() but it accepts different arguments.

    Note the structure of the while loops is incorrect as eof() should be checked immediately after a read operation. A common way of coding the loop is:

    while (getline(f2, line2))
    {
        mParse(line2);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm trying to take an input from a user using Scanner(System.in) but when
Hey I'm trying to take a String input from the user (in this case
I am trying to using the JS to take user input and modify certain
I was trying to make a code that will take input from a user
I am trying to take a single input from the user and delete some
I'm trying to take a user input, turn it into a JS variable, and
I'm trying to take an integer from the user. I'm using cin.ignore to make
I'm trying to take user form input and display it back to the user,
I'm trying to take the user input, which may or may not have a
In this loop, I'm trying to take user input and continually put it in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.