HELP WITH CIN.GET  
Author Message
Sportsdude





PostPosted: Visual C++ Language, HELP WITH CIN.GET Top

my program builds and runs
when i try to use cin.get while the program is running it doesn't input using cin.get

here is my code(note it is not entirely done but it still builds/works):

#include <iostream>
#include <fstream>

using namespace std;
int main()
{

ofstream out;
char task[50];
char due_date[50];
char classnumber[50];

out.open("todo.txt");
if (!out)
cout<<"error"<<endl;
else
{
cout<<"What is your task name :"<<endl;
cin.get(task,50,'/n');
cin.get();
cout<<"What is the due date :"<<endl;
cin.get(due_date,50,'/n');
cin.get();
cout<<"What is the class # :"<<endl;
cin.get(classnumber,50,'/n');
cin.get();

out<<task;
out.put(':');
out.put(' ');
out<<due_date;
out.put(':');
out.put(' ');
out<<classnumber;
out.put(':');
out.put(' ');
}

}






Visual C++14  
 
 
Bite Qiu - MSFT





PostPosted: Visual C++ Language, HELP WITH CIN.GET Top

hello

The delimiter '\n' will put stay in the input buffer, so your input buffer is always like:

'\n'something you input'\n

so the get() always meet its delimiter at first char in the input buffer, so nothing gonna read. you can always find where a '\n' will appear, and use get() to eat this '\n', but a easier way is to use getline().

cout<<"What is your task name :"<<endl;

cin.getline(task,50);

cout<<"What is the due date :"<<endl;

cin.getline(due_date,50);

cout<<"What is the class # :"<<endl;

cin.getline(classnumber,50);

thanks

Bite



 
 
Sportsdude





PostPosted: Visual C++ Language, HELP WITH CIN.GET Top

thanks for the help that works but this is a school project and i am not allowed to use any string class functions sorry i forgot to mention it


 
 
Simple Samples





PostPosted: Visual C++ Language, HELP WITH CIN.GET Top

Where do you see a string class function there

It is unfortunate you can't get a better instructor; the string class is part of C++ and you should be allowed to use it, especially since you can use most of the rest of the standard.



 
 
Sportsdude





PostPosted: Visual C++ Language, HELP WITH CIN.GET Top

i am not allowed to use the cin.getline();


 
 
Simple Samples





PostPosted: Visual C++ Language, HELP WITH CIN.GET Top

What were you taught It will be much easier for you to read the materials you were supposed to read than for us to guess at what you can do.



 
 
Bite Qiu - MSFT





PostPosted: Visual C++ Language, HELP WITH CIN.GET Top

hello,

I think we were looking on a wrong directions, the only thing you need to do is to modify the '/n' to '\n':

#include <iostream>

#include <fstream>

using namespace std;

int main()

{

ofstream out;

char task[50];

char due_date[50];

char classnumber[50];

out.open("todo.txt");

if (!out)

cout<<"error"<<endl;

else

{

cout<<"What is your task name :"<<endl;

cin.get(task,50,'\n');

cin.get();

cout<<"What is the due date :"<<endl;

cin.get(due_date,50,'\n');

cin.get();

cout<<"What is the class # :"<<endl;

cin.get(classnumber,50,'\n');

cin.get();

out<<task;

out.put(':');

out.put(' ');

out<<due_date;

out.put(':');

out.put(' ');

out<<classnumber;

out.put(':');

out.put(' ');

}

}

thanks

bite



 
 
Simple Samples





PostPosted: Visual C++ Language, HELP WITH CIN.GET Top

I got confused. My last reply was partially the result of confusing this question with a similar one.

The code posted with the corrections works for me so I hope it works for Sportsdude too.



 
 
Sportsdude





PostPosted: Visual C++ Language, HELP WITH CIN.GET Top

thanks for all the help my problem was i put '/n' as a return instead of '\n'