Space problem c++

Hi there,I am new to programming and I am having a lil bit problem with my code, I can't get to use space in the program i am trying to create.
Actually i am typing address and in the output it doesn't give spaces.
I tried to use getline and cin.getline statements but it skips the first word e.g if I write "House number xxxx" it starts from "number" and skips House,rest of the program is working fine,any help will be appreciated.

I figured it out, I didn't have to use cin, i just had to create a program that gives the output, thanks for help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
using namespace std;
int main()
{
	string FirstName, LastName;
	cout << "Please enter your Name (first then last): ";
	cin >> FirstName >> LastName;
	string FfirstName, FlastName;
	cout << "Please enter you Father's name: ";
	cin >> FfirstName >> FlastName;
	string Religion;
	cout << "Please enter your religion: ";
	cin >> Religion;
	string Cell_No;
	cout << "Please enter your cell number: ";
	cin >> Cell_No;
	string Address;
	cout << "Please enter your address:";
	cin >> Address;
	getline (cin,Address);
	cin.ignore();
	cout << "Name: "<<FirstName <<" "<< LastName<<""<<endl;
	cout << "Father's Name: "<<FfirstName <<" "<<FlastName<<"" <<endl;
	cout << "Religion: "<<Religion<<""<<endl;
	cout << "Cell-No: "<<Cell_No<<""<<endl;
	cout << "Address: "<<Address<<""<<endl;
	
		return 0;
}
 
Last edited on
Line 19: get first word into variable Address.
Line 20: get rest of line into variable Address.

See what is wrong?

Line 21: you don't need to cin.ignore() after a getline().

Here's some additional reading that may help:
http://www.cplusplus.com/forum/beginner/115747/#msg634709

Hope this helps.
Topic archived. No new replies allowed.