I have seen someone using "clrscr". What's its function? I guess it stands for 'clear screen'. But which screen it want to clear. And what header file to include to make it functional? Please tell me.
1 2 3 4 5 6 7 8 9
#include <iostream>
void main()
{
clrscr();
...
}
I have been told "\n" and "endl" are almost the same but there are some technical differences between the two. Is there also something such as "newl" which is also used for new line?
When I want to use "endl" I do it the following way and it works.
Using "endl":
This will work:
cout << "Yes, I'm fine" << endl;
This won't work:
cout << "Yes, I'm fine. \endl";
Using "\n":
This will work:
1 2
cout << "Yes, I'm fine.\n";
cout << "What about you?\n";
1) clrscr() is a non-standard function, don't use it
2) std::endl something you send to a stream that outputs a '\n' character then flushes the buffer
3) '\n' is a special character, different from std::endl, it represents a "newline" (although what that means might be different on your OS)
1 2 3
std::cout<<"Stuff"<<std::endl;
//is the same as
std::cout<<"Stuff\n"<<std::flush;
Okay, I won't use "clrscr()" but can you tell what its not-standard function is?
And what do you really mean by "non-standard" above? Does it have something to do with C++ and "Standard C++" (although I don't know the distinction between the two).
By non-standart function you can understand that it is not included in C++ libraries. For example the functions you create by yourself are non-standart functions ;)
I also use function "system()" such as "system("pause")", is it also non-standard. And it works without including any header file - although I was told I would need to include "<windows.h>". I'm using Dev-C++. Please guide me on this. Thanks.
System("command"); is a function call that will make use of any of the commands available in your windows command prompt. Go to StartMenu->Run and type in cmd and hit enter, that will bring up a command prompt. If you type cls into the command prompt and hit enter it will clear the screen of the console. Similarly when you use a System("cls"); call in your code it will clear the console screen at run time.
-ceruleus
edit: if it is of any help the code for clrscr() would probably be something like this:
"The C++ standard" refers to the international ISO C++ standard. If a function/expression/marcro/whatever is in the standard, then it will. But for those not in the standard, it is not guaranteed that they will remain useful (e.g. understandable by new compilers) in, who knows, 10 years time. It is an evolving language.
BTW, system() is a standard function. You find it by #including <cstdlib>.
The problems are that it opens security vulnerabilities, and that it is inherently OS-dependant. For example
system("cls");
will only work on Windows. On Unix, you would have to say