C/C++ The following C++ program does not compile

  • Thread starter Thread starter soul5
  • Start date Start date
  • Tags Tags
    C++ Program
AI Thread Summary
The discussion centers on the correct syntax for using the `cout` statement in C++. The initial example, `cout << "2 + 3 * 5 = " 2+3*5 << endl;`, is identified as incorrect due to improper syntax. The correct version, `cout << "2 + 3 * 5 = " << (2+3*5) << endl;`, is confirmed to be valid. Participants emphasize the necessity of using the `<<` operator to separate string outputs from variable outputs in C++. There is a suggestion to compile and test the second example to verify its functionality, highlighting the importance of syntax in avoiding compilation errors.
soul5
Messages
63
Reaction score
0
cout << "2 + 3 * 5 = " 2+3*5 << endl;


do I just need to put it as

cout << "2 + 3 * 5=" << (2+3*5) << endl;
 
Technology news on Phys.org
soul5 said:
cout << "2 + 3 * 5 = " 2+3*5 << endl;do I just need to put it as

cout << "2 + 3 * 5=" << (2+3*5) << endl;

First one is bad, second one looks good.

Why don't you simply compile the second, run and test it? ooO, does the second one also throws error?
 
I'm pretty sure you can't mix string output together with variables. You must separate them into with <<.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top