how to pause the display in console?
hi
when we write our code involving the use of display console all the messages in the program are displayed one after another as the program is executed. however i want the execution to stop and prompt the user for proceed permission if certain conditions arise.
how can i do that?
i'm using VC++ version 6.0 if thats of any help.
sam
Re: how to pause the display in console?
Use printf() to display the msg and scanf() to get the option from the user.
Regards
MJV
Re: how to pause the display in console?
Code:
#include <string>
#include <iostream>
int main()
{
std::string t;
std::cout << "Enter your first name: ";
std::cin >> t;
std>>cout << "Hello " << t <<std::endl;
return 0;
}
Re: how to pause the display in console?
Would you describe more that what sort of conditions and how would u like to change the flow of the program. There are different ways, like if you only want to pause the execution, you can use system("pause"); or you can use getch/getche or cin.get(), for user input, you can use scanf as already mentioned or cin.
I guess a sample code will be better, if you post that demonstrate how you are implementing your program.
Re: how to pause the display in console?
well Ejaz u just abt got the hang of the real problem.
right now i've a program written to do certain parameter checking in a data file.
my point is i want the program to pause execution(and not stop) and then prompt the user for further instructions like whether it is proceed with its execution or stop and create an error log file . BTW while u r on this can also tell me how to create the error log file at run time as i have to do this whether i'm able to the previous task or not.
thnx 4 ur previous suggestion though i'll think abt it in the meanwhile.
sam
1 Attachment(s)
Re: how to pause the display in console?
My example in the previous basically answers your first problem.
About the logfile...there are many different ways depending on the way you want to keep your logfile...
I have attached a small logger class which will create a simple buffered logfile...
I had to remove some of my wrapper classes for threads and semaphores etc. but it should work...let me know if not...
Re: how to pause the display in console?
Code:
int main()
{
// Some processing
cout << "Options" << endl;
cout << "(S)ave to log" << endl;
cout << "(R)ead from log" << endl;
cout << "S(o)mething else" << endl;
char choice = getche();
cout << endl;
if ( 'S' == choice || 's' == choice )
{
cout << "Saving data to log" << endl;
// Save data to file
}
else if ('R' == choice || 'r' == choice )
{
cout << "Reading data from log" << endl;
// Read data from file
}
else
cout << "Doing something else";
return(0);
}
Re: how to pause the display in console?
thnx a whole lot Andreas and Ejaz.
i think i've got the solution to it but will have to work on it little. honestly i didnt expect answers so soon. well anywyz now that i've got them i have something to work on. and Ejaz U have literally spoonfed me. thnx again to u.
BTW Andreas i may not be able to go htru ur attached file for a while, however i've downloaded it and will look into it asap.
till then frnds
ciao
sam:)
Re: how to pause the display in console?
hi there Andreas
sorry to bug u again.
remember the file u sent attached to me. well i tried compiling the whole thing but i keep coming up with a particular error while compilation. my compiler says:
Compiling...
LogFile.cpp
d:\samdownloads\cg-andreas\logfile.cpp(10) : fatal error C1083: Cannot open include file: 'LogFile.hpp': No such file or directory
Error executing cl.exe.
LogFile.exe - 1 error(s), 0 warning(s)
now i cant figure out why this is happening. :confused: mebbe i'm missing something, but what? anywyz just in case u wanna know i'm using microsoft visual C++ version 6.0 compiler.
sam
Re: how to pause the display in console?
hi there again
well i got past the previous error message but now there is a new trouble.
whenever i try to compile i'm given the message : " no compile tools associated with the file extension" this message is appearing for LogFile.hpp.
any clue as to why?
sam
Re: how to pause the display in console?
Quote:
Originally Posted by techsam
d:\samdownloads\cg-andreas\logfile.cpp(10) : fatal error C1083: Cannot open include file: 'LogFile.hpp': No such file or directory
Error executing cl.exe.
Well...did you set the path to the header file correctly (in the project options)? The sample code relies on that...
Re: how to pause the display in console?
Quote:
Originally Posted by techsam
hi there again
well i got past the previous error message but now there is a new trouble.
whenever i try to compile i'm given the message : " no compile tools associated with the file extension" this message is appearing for LogFile.hpp.
any clue as to why?
sam
Well...are you testing this within a console application? I do not have a test program available here, however, I will upload one when I get back home....