C++ Programming Tutorial 25 – getline for Strings



Python Bootcamp – https://www.codebreakthrough.com/python-bootcamp

💯 FREE Courses (100+ hours) – https://calcur.tech/all-in-ones
🐍 Python Course – https://calcur.tech/python-courses

✅ Data Structures & Algorithms – https://calcur.tech/dsa-youtube

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

✉️ Newsletter – https://calcur.tech/newsletter
📸 Instagram – https://www.instagram.com/CalebCurry
🐦 Twitter – https://twitter.com/calebCurry
🔗 LinkedIn – https://www.linkedin.com/in/calebcurry
▶️ Subscribe – http://calcur.tech/subscribe
👨🏻‍🎓 Courses – https://www.codebreakthrough.com

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

↪ My Amazon Store – https://www.amazon.com/shop/calebcurry
🅿 Patreon – http://calcur.tech/patreon-calebcurry
🅖 GitHub Sponsors – https://github.com/sponsors/CalebCurry
Ⓟ Paypal – http://paypal.me/calcur

🅑 Bitcoin – 3HnF1SWTzo1dCU7RwFLhgk7SYiVfV37Pbq
🅔 Eth – 0x350139af84b60d075a3a0379716040b63f6D3853
📈 Buy Bitcoin – https://calcur.tech/crypto
Reserve the Ruby Steel crypto rewards card and get a $25 bonus (use affiliate code “Caleb”) – https://calcur.tech/crypto

18 thoughts on “C++ Programming Tutorial 25 – getline for Strings

  1. 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?

  2. 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.

  3. 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.

  4. int main(){
    int t{};
    cout<<"enter how many time do u want this to happenn";
    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 .

  5. 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?

Leave a Reply

Your email address will not be published. Required fields are marked *