Click here to Skip to main content
15,889,858 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i input a sentence (question) string from console ,it doesnt take the whole sentence rather takes only word as a ( q.ques )


code

C#
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
void main(){
	struct quiz//structure for storing questions
{
	char ques[200];
	char op1[30];
	char op2[30];
	char op3[30];
	char op4[30];
	char z[2];
}q;
ofstream outf("item.csv");
cout<<"enter question :"<<endl;
cin>>q.ques;
outf<<q.ques<<"\n";
cout<<"enter option A :"<<endl;
cin>>q.op1;
outf<<q.op1<<" ";
cout<<"enter option B :"<<endl;
cin>>q.op2;
outf<<q.op2<<" ";
cout<<"enter option C:"<<endl;
cin>>q.op3;
outf<<q.op3<<" ";
cout<<"enter option D :"<<endl;
cin>>q.op4;
outf<<q.op4<<" ";
cout<<"enter correct option :"<<endl;
cin>>q.z;
outf<<q.z<<endl;
outf.close();//end of file for storing in file 
ifstream inf("item.csv");//opening file for reading
inf>>q.ques;
inf>>q.op1;
inf>>q.op2;
inf>>q.op3;
inf>>q.z;
cout<<endl;
cout<<"question"<<endl<<q.ques<<endl;
cout<<q.op1<<" "<<q.op2<<" "<<q.op3<<" "<<q.op4<<endl;
cout<<"correct ansrer no"<<"  "<<q.z<<endl;
getch();
inf.close();//closing file




}//end of main function


What I have tried:

i have runned this program in turbo c++ ,as a console application
Posted
Updated 6-Mar-16 21:47pm
Comments
Afzaal Ahmad Zeeshan 7-Mar-16 4:43am    
Also, get rid of Turbo C++. Instead, use (better) alternatives for C++ compilers, such as GCC (cross-platform) or Visual C++ (on Windows).

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

Run your program with TC++ debugger.
Track changes in variables as you debug the program line by line. You will see exactly what your program do.
 
Share this answer
 
That is because cin only reads the next token. If you want to read the entire sentence then you need to call cin.getline. See basic_istream::getline[^] for full details.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900