Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,990 questions

51,935 answers

573 users

How to input string and integer in C++

1 Answer

0 votes
#include <iostream>
#include <string>

using std::cout;
using std::cin;
using std::endl;
using std::string;

int main()
{
	string name, s;
	int age;

	cout << "Enter name: ";
	getline(cin, name);
	cout << "Enter age: ";
	getline(cin, s);
	age = stoi(s);

	cout << endl << name << " " << age << endl;

	return 0;
}


/*
run:

Enter name: R2D2
Enter age: 48

R2D2 48

*/

 



answered May 24, 2018 by avibootz

Related questions

1 answer 139 views
1 answer 143 views
1 answer 117 views
1 answer 150 views
2 answers 159 views
159 views asked Jun 6, 2017 by avibootz
1 answer 125 views
125 views asked Jul 12, 2023 by avibootz
...