How to accept user input in C++? ⌨️

preview_player
Показать описание
C++ How to accept user input cin tutorial example explained
Рекомендации по теме
Комментарии
Автор

#include <iostream>

// cout << (insertion operator)
// cin >> (extraction operator)

int main()
{
std::string name;
int age;

std::cout << "What's your full name?: ";
std::getline(std::cin >> std::ws, name);

std::cout << "What's your age?: ";
std::cin >> age;

std::cout << "Hello " << name << '\n';
std::cout << "You are " << age << " years old";

return 0;
}

BroCodez
Автор

In case people were wondering if they had an issue with the getline not having the namespace add #include <string>. Then the function will work as intended. Think Bro forgot to show that step.

cmdrrespawn
Автор

It's a pleasure have you back bro!

alexman
Автор

I'm glad your back! I wanted some refresher and it didn't take long to learn something new (std::ws). Thank you and please keep doin' what you do!

mkez
Автор

Thank You Sooo Much Thsi Helped Me Alot!

scpf
Автор

good work dude
thanx for ur eforts
greetings from Egypt

ahmadosama
Автор

Yoo bro is back!! Btw can you do native android development in Java series?

abhimanyu-kapoor
Автор

Great tutorial as always man! Quick petition. Can you do minesweeper using Java? I will really like seeing a tutorial about this.

luisciprian
Автор

What laptop can you guys recommend for programming?

forkspoon
Автор

Help, when i check run in terminal it says "Unable to write into user settings. Please open the user settings to correct errors/warnings in it and try again."

mlp
Автор

What is Typescript compared to Javascript? Is it a framework of JS?

UnderArea
Автор

Where would you start to learn code now if you had 0 knowledge? is the school/ college way better than self learning? and how did you start learning and from where

bogdan
Автор

So when using a mix of cin and getline you better use cin>>ws inside the get line

someoneall
Автор

Currency output in c# used .ToString("c") ... How do I do it in c++?

jvaxjoaopaulo
Автор

Hello it said namespace "std" did not have member "getline" i did #include <string> and it fixed it though?

BeatRunner
Автор

way more complex than python, but pretty cool
i feel like with just a little more experience I can hack Microsoft

oximas-oevf