C++ Programming Tutorial 25 - getline for Strings

preview_player
Показать описание


~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~

🅑 Bitcoin - 3HnF1SWTzo1dCU7RwFLhgk7SYiVfV37Pbq
🅔 Eth - 0x350139af84b60d075a3a0379716040b63f6D3853
Рекомендации по теме
Комментарии
Автор

Thank you for explaining the difference between cin.getline() and getline()!

Notatrace
Автор

for people whos getline doesn't work for seemingly no reason, use cin.ignore() before calling it. worked for me.

typical_yt
Автор

Obi Wan: Hello
There

Grievious: General
Kenobi

franciscorosario
Автор

It can be used to get a line from a file too. I believe.

braindeveloperdimensional
Автор

Here is a question for Curry - scope resolution operator :: is used for cin, cout, string. I can understand that. But getline is used without scope resolution operator. Compiler accepts the same. It is not expecting istream::getline. Why is it so? Thanks in advance. Your teaching is a really good for C++ programmers.

igetgrad
Автор

thanks for explaining the differenc between cin and getline

eatyourcereal
Автор

What If you have two getline() functions in a row;

example:
cout << "Enter name: ";
getline(cin, name);

cout << "Enter address: ";
getline(cin, address);

it skips the next getline. and doesn't prompt for user input.

devianttt
Автор

Hey Caleb, had a question. At the start you'd declared 'greeting' and then 'left_over'. Then, you took the input as 'Hello World' which were stored as greeting=Hello and left_over=There. I did the same where I declared 'firstword' and 'secondword' and took the input as 'Hello There' and printed them in the order 'firstword' and then 'secondword' but what I'm getting as input is first 'There' and then 'Hello' meaning 'There' was stored in firstword and 'Hello' in secondword. I don't know why that's happening. Can you help?

RM-lbxw
Автор

With this the only way I could pull off the user input being beside each other was to implement the (;) at the beginning of the std::cout

ScraitStressin
Автор

cool explanation.. i am unable to use 'cin.getline()' .. i am getting an error like ' no matching function for call to '.. i have searched for it.. in geek for geeks, they have mentioned it will take 2 or 3 parameters and 3rd parameter being the delimiter.. 3rd parameter is optional.. 2nd is the max size and 1st is the variable.. but they have used C character array here but not a string variable.. sir, could you please explain it to me? How can we use '.getline()' in c++?

gouthamtadali
Автор

sir iam using for visual studio but not working getline () .getline() function identifier not found .pls give me a solution

kishoresk
Автор

Would that work with C-string, I mean if I want to input a C-string which is considered an array of course and it has spaces would I use getline also or is there any other way?

hesham
Автор

how about the space? cin automatically ignores them??

kenneth
Автор

int main(){
int t{};
cout<<"enter how many time do u want this to happen\n";
cin>>t;

while(t--){
string s1{};
cout<<"enter s1 : "<<endl;
getline(cin, s1);
cout<<"my string input for loop : " <<t<< "is "<<s1<<endl;
}
}
//whats wrong here : the getline function dont work for the first iteration .
//i have started c++ a week before and trying to figure out how strings work in c++ .so this is just sample code to test getline function .

aniketshirke
Автор

use
using namespace instead of writing std every tim, e

mohammad_bilal
Автор

Is anyone else's getline skipping the first word too?

andrewgreen
Автор

I think it would be a cin not to learn about C++ IO.

PunmasterSTP