GuidePedia

0
Cin with space in character string c++. Now you can understand with basic program.
In case of character string :
#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <string>
using namespace std;

int main()
{
	char name[20];
	cout << "Enter Your Name:";
	cin.getline(name, 20);
	cout << "My Name is :" << name<<endl;

	_getch();
	return 0;
}

Output

How to Get C++ cin input with spaces in string or char string?

Cin with space a string type values like string name.
In case of Simple string :

#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string name;
	cout << "Enter Your Name:";
	getline(cin, name);
	cout << "My Name is :" << name<<endl;

	_getch();
	return 0;
}

Output

How to Get C++ cin input with spaces in string or char string?



Post a Comment

 
Top