0

When I'm trying to run a simple hello world script it sends this error message, Can anyone help me solving this issue?

[Running] cd "c:\Users\NickT\OneDrive\Documents\C++ Tutorial\" && g++ helloworld.cpp -o helloworld && "c:\Users\NickT\OneDrive\Documents\C++ Tutorial\"helloworld
helloworld.cpp: In function `int main()':
helloworld.cpp:9: error: expected primary-expression before "msg"
helloworld.cpp:9: error: expected `;' before "msg"
helloworld.cpp:11: error: expected primary-expression before "const"
helloworld.cpp:11: error: expected `;' before "const"
helloworld.cpp:16: error: expected primary-expression before '}' token
helloworld.cpp:16: error: expected `)' before '}' token
helloworld.cpp:16: error: expected primary-expression before '}' token
helloworld.cpp:16: error: expected `;' before '}' token

[Done] exited with code=1 in 0.233 seconds

This is the written code

#include <iostream>

int main(){
    std::cout << "Hello World" << std::endl;
    return 0;
}
  • 4
    Can you share the code you have written? – tomerpacific May 05 '20 at 07:06
  • Looks like you forgot a `;`. – tadman May 05 '20 at 07:07
  • #include int main(){ std::cout << "Hello World" << std::endl; return 0; } – Nick Johnson May 05 '20 at 07:12
  • @NickJohnson That's not the code that causes those errors. Please [edit] your question to show the real code. – Lukas-T May 05 '20 at 07:22
  • Can you copy the code from `helloworld.cpp`? it's hard to diagnose the compiler error without looking at the code. – jpuriol May 05 '20 at 07:38
  • 1
    Again, please post the _actual_ code. This code [compiles fine](http://coliru.stacked-crooked.com/a/7945ac7e48e5c914). The errors mention line 9 and 16. This code doesn't even have 9 lines. It contains neither `const` nor an identifier `msg`. Maybe you are compiling the wrong code? Please double check. – Lukas-T May 05 '20 at 07:45

1 Answers1

1

I revised the code you have posted as well as added a piece of code to utilize the namespace std. Analyzing the output from your compiler it does seem that you may have not added a semi colon. Alternatively, it's not necessary to reference the std library when calling it's functions but it's up to your preference. It doesn't seem though to be an issue with your code either. Can you post the actual code you've attempted to compile because there doesn't seem to be an issue with this piece.

Revised Code:

#include <iostream>

using namespace std;

int main() {
  std::cout << "Hello World" << std::endl;
  return 0;
}
  • 1
    Please note that `using namespaace std` is [considered bad practice](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice). And it has no use whatsoever when you still write the `std::` ;) – Lukas-T May 05 '20 at 07:27