+ 1

How we can show output without using cout in c++?

I'm new for sololearn. plz help me.

25th Oct 2018, 4:27 AM
Arvind Mehta
Arvind Mehta - avatar
8 Answers
+ 8
You can use printf function. http://www.cplusplus.com/reference/cstdio/printf/ You will need to include <cstdio> header. NOTE: if you are printing value of std::string instead of C-String (char array) you will have to use the value from <string object>.data(), or <string object>.c_str(). Example: #include <string> #include <cstdio> int main() { std::string sol {"SoloLearn"}; const char *com {"Community"}; int year {2018}; printf("%s %s %d", sol.c_str(), com, year); return 0; } Hth, cmiiw
25th Oct 2018, 4:59 AM
Ipang
+ 5
Assuming the intent of the question is "write something to screen", then along with Ipang 's explanation which has some C flavor, there are two other ostream objects which are tied to standard error stream (stderr) -- which is a different stream than stdout -- and somehow capable of handling the output-to-screen needs and we can abuse them shamelessly! 1. std::cerr Usually writes to the same device as the standard output -- Same as std::cout. By default, writings to std::cerr are not buffered -- which means it's slower than std::cout -- and for the most part "used for error message or other output that is not part of the normal logic of the program". 2. std::clog More like std::cout -- which means the stream is buffered -- and as the name suggests, is used to report program's information to a log file or screen.
25th Oct 2018, 8:34 AM
Babak
Babak - avatar
+ 4
Şerban Daniela-Mihaela LOL! NOTHING! NOTHING! NOTHING! I guess I've been encountered this question for 1,001 times, here! It gets implicitly defined for you. So don't worry about it anymore, OK?! ;)
28th Oct 2018, 7:04 PM
Babak
Babak - avatar
+ 3
thanks for your valuable answer
25th Oct 2018, 8:04 AM
Arvind Mehta
Arvind Mehta - avatar
+ 2
You're very welcome : )
25th Oct 2018, 8:06 AM
Ipang
+ 2
Hi. Somebody can tell me what happens if i don't use the return 0? I tried and is the same result. Many thanks. :)
28th Oct 2018, 6:43 PM
Şerban Daniela-Mihaela
Şerban Daniela-Mihaela - avatar
+ 1
Printf
18th Dec 2018, 2:28 PM
ŠšŠ¾Š½ŃŃ‚Š°Š½Ń‚ŠøŠ½Š¾Š² Š˜Š²Š°Š½
0
You may use printf ("example");
22nd Dec 2018, 8:12 AM
Yakhyokhon
Yakhyokhon - avatar