#include<iostream>
#include<string>
using namespace std;
struct one
{
	char name_book[80];
	char name_author[80];
	int no_of_books;
}one1[500];

int insert()
{
	int i,j;
	cout<<"Enter the No. of Books you want to enter : ";
	cin>>i;
	cout<<endl;
	for(j=0;j<i;j++)
	{
		cout<<"Enter the name of book "<<j+1<<" : ";
		cin>>one1[j].name_book;
		cout<<"Enter the name of the Author of the book "<<j+1<<" : ";
		cin>>one1[j].name_author;
		cout<<"Enter the number of books in this title "<<" : ";
		cin>>one1[j].no_of_books;
		cout<<"\n";
	}
	for(j=0;j<i;j++)
	{
		cout<<"The name of book "<<j+1<<" is : ";
		cout<<one1[j].name_book;
		cout<<endl;
		cout<<"The author's name for book "<<j+1<<" is : ";
		cout<<one1[j].name_author;
		cout<<endl;
		cout<<"The number of books in this title are "<<"book is : ";
		cout<<one1[j].no_of_books;
		cout<<endl;

	}
	return 0;
}

void main()
{
	insert();
}

The problem is in line 20 i have to use cin and am not able to use cin.getline
but cin.getline should be used as cin breaks when it reads a space that's why cin.getline should be used but when i use cin.getline the entry for teh 1st book is not taken but it runs normally for the entry of second book plz help!!

Comments
Though you have used code-tags. Void main is very bad!
if( post == 1 && code_tags ) rep++; :P

You'll have to describe your problem clearer then this.
- What is your input ?
- What is your output?
- What ouput were you expecting?

And what happens when the user enters a number bigger then 500?

when i run this prigram using cin.getline(one1[j].name_book,80);
in line 20

the output is

Enter the No. of Books you want to enter : 2

Enter the name of book 1 : Enter the name of the Author of the book 1 : qwerty
Enter the number of books in this title : 5

Enter the name of book 2 : Enter the name of the Author of the book 2 : qwerty
Enter the number of books in this title : 50

The name of book 1 is :
The author's name for book 1 is : qwerty
The number of books in this title are book is : 5
The name of book 2 is :
The author's name for book 2 is : qwerty
The number of books in this title are book is : 50
Press any key to continue


see the program doesn't take the input of name of book but it does when i use cin but i want to use cin.getline even gets doesn't work

You have to clear the input buffer. You could use something like: cin.ignore(80,'\n'); [edit]
Whoops, I was too slow and AD already posted the answer ;)

This article has been dead for over six months. Start a new discussion instead.