Can you print text like this ... cout << ("hello world"); | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can you print text like this ... cout << ("hello world");

24th Jul 2017, 10:36 AM
chidori
chidori - avatar
4 Answers
+ 2
Sure why not? also can cout << (const char*)("hello world");
24th Jul 2017, 11:03 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 2
Do cout << "hello world"; without the braces
24th Jul 2017, 11:39 AM
BwD//Felix Janetzki
BwD//Felix Janetzki - avatar
+ 1
Yep you can ! "hello world" is a string. A string is an array of char. Like int types, you can add two string together: int a(5), b(9); cout<<a+b; // output : 14 string a("hello "), b("world"); cout<<a+b;//output : hello world now, look : int a(6); int b(5); int v(2); cout<<a+(b*v);//output : 16 the brackets are here to tell the priority is to b*v. However, * has the priority on +. So the brackets are useless, but it's not an error. So ("hello world") is like "hello world" and you can write cout<<("hello world"); but that's USELESS. You can even write ((((("hello world"))))); Ask if there is something you don't understand
24th Jul 2017, 11:52 AM
Jojo
0
i think it'll give u error....(specifically syntax error).
24th Jul 2017, 11:26 AM
Shreyas Subhedar
Shreyas Subhedar - avatar