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

  • SEARCH
  • Home
  • 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 3614026
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:11:49+00:00 2026-05-18T22:11:49+00:00

string text; getline(text.c_str(),256); 1) I am getting an error error: no matching function for

  • 0
string text;
getline(text.c_str(),256);

1) I am getting an error “error: no matching function for call to ‘getline(const char*, int)”
What’s wrong in the above since text.c_str() also returns a pointer to array of characters.

If I write like this

char text[256]
cin.getline(text, 256 ,'\n'); 

it works fine. What’s the difference between cin.getline and getline?

2) How come

text string;
getline(cin,text,'\n') 

accepts the whole line as the input. Where is the pointer to array of characters in this one?

  • 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-05-18T22:11:50+00:00Added an answer on May 18, 2026 at 10:11 pm

    text.c_str() returns a const char *. You may not use it to modify the contents of the string, in any way. It only exists so that you can pass the string data to old C API functions without having to make a copy. You are not allowed to make changes because there is no way that the string object that holds the data could possibly find out about them, and therefore this would allow you to break the string’s invariants.

    Furthermore, std::getline accepts completely different parameters. (You would know this if you took two seconds to type ‘std::getline’ into Google.) The error means exactly what it says: “no matching function for call” means “you can’t call the function with these kinds of parameters”, because every overload of the function accepts something different (and incompatible).

    std::getline accepts these parameters:

    • A stream. You have to pass this because otherwise it doesn’t know where to read from.
    • A string object to read into. NOT a char buffer.
    • Optionally, a line delimiter char (same as the stream getline member function).

    There is not really any such function as “cin.getline”. What you are calling is the member function “getline” of the object “cin” – a global variable that gets defined for you when you #include <iostream>. We normally refer to this according to what class the function is defined in – thus, std::istream::getline.

    std::istream::getline accepts these parameters:

    • A char buffer.
    • Optionally, a line delimiter char.

    It does not need a stream parameter because it is a member function of the stream: it uses whatever stream we called it with.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following intentionally trivial function: void ReplaceSome(ref string text) { StringBuilder sb
Is there a built in Javascript function to turn the text string of a
Say I have an array of values: string[] text = new string[] { val1,
I have a text string structured like this: = Some Heading (1) Some text
I have a multiline text string (e.g. Stuff\nMore Stuff\nYet More Stuff), and I want
I am downloading a text string from a web service into an RBuf8 using
What is the maximum length for the text string contained in a CEdit control
I am trying to insert a very long text string into a MySQL Blob
What is the best way to verify/test that a text string is serialized to
What is a good regular expression that can validate a text string to make

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.