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..
#include <fstream>
#include <iostream>
#include <conio.h>
#include <string>
#include <cstring>
usingnamespace 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;
}
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.