How can i get input from user in array

How can i get input from user which is his name?by default i used string copy function with my name Danish Ilyas.but i want user Enter his name from keyboard..

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
31
32
33
34
35
36
37
38
39
40
  #include <fstream>
#include <iostream>
#include <conio.h>
#include <string>
#include <cstring>
using namespace std;
struct book 
{
	int id;
	char name[20];
	double gpa;
};
int main ()
{
book b1;
ID:
cout<<"Please Enter Your ID :";
cin>>b1.id;
if(b1.id<1000){
	goto ID;}

cout<<"\nPlease Enter Your Name :"; //how can i get user input in this scenario.i want to char array to get input from user.
strcpy(b1.name,"Danish Ilyas");//which code line should i use to get input from user.i want that user enter his name from keyboard.
CGPA:
cout<<"\nPlease Enter your GPA :";
cin>>b1.gpa;
if(b1.gpa<0){
	goto CGPA;
}

cout<<"\nStudent ID :"<<b1.id;
cout<<"\nStudent Name :"<<b1.name;
cout<<"\nStudent GPA :"<<b1.gpa;
getch();	


   return 0;
}

The formatted input stops on whitespace, i.e. reads only the first word:
http://www.cplusplus.com/reference/istream/istream/operator-free/

The unformatted input reads up to delimiter:
http://www.cplusplus.com/reference/istream/istream/getline/


You do include <fstream>, but you don't use anything from it.
You do include <string>, but you don't use std::string.
You could use std::string instead of char array. It would be safer and more convenient.


Consider replacing the goto structures with while or do while loops.
https://en.wikipedia.org/wiki/Considered_harmful
http://herbsutter.com/2013/03/14/words-of-wisdom-bjarne-stroustrup/
i know these settings comes from editor setting.every new source code page start from these header files.i m so lazy so i dont delete them
Topic archived. No new replies allowed.