Error: expected unqualified-id before '{' token

Jun 17, 2013 at 11:03am
Hi, I am using an online compiler, and I have an error on line 10 of my code, apparently. The error message reads this:

main.cpp:10:1: error: expected unqualified-id before '{' token

This is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  #include <iostream>
#include <string>

int main();

using namespace std;

//Last Edited: 09:28 17/06/2013

{

    string startUp = "Starting Program... !$%^&%5&^%£4%&7^*&(^&(%$^*";
    cout << startUp << endl;
    sleep(400);
    cout << "Testing Protocol: Captial - A a AA aa Aa aA" << endl;
    sleep(400);
    cout << "Test Succesful. Scanning for files..." << endl;
    sleep(1000);
    cout << "Virus Found - U://ICT//" << endl;
    sleep(200);
    cout << "Terminating program ..." << endl;
    sleep(200);
    cout << "**&^&%$^$%&%^*$£%^*£***(*£&%!" << endl;
    sleep(200);

    return 0;
}


What is it, and what is wrong with the brace?

Thanks!
Jun 17, 2013 at 11:09am
Move using namespace std; to line 3.
Jun 17, 2013 at 12:42pm
What pebble said, then remove the semi-colon from the end of line 4.
Jun 27, 2013 at 3:32pm
Hi everybody, my problem is fixed, but as you can see, the sleep function is there with no executor. Can anybody here tell me how to activate/execute the sleep function? (Forgive me, I am using very simple terminology because I am a beginner, and I am not yet used to all of the correct phrases used in C++ programing.)
Jun 27, 2013 at 4:13pm
I don't know what you mean by "no executor". You're certainly calling the sleep function several times in the code you've posted. What makes you think you aren't?
Jun 27, 2013 at 4:22pm
I haven't used a '#include' or 'int()' function/piece of code to activate the sleep function. How do I get the sleep function to work?
Jun 27, 2013 at 5:07pm
I haven't used a '#include'

Is your code compiling? If not, then you need to #include the correct header file.

If it is compiling, then you can assume a function declaration is in there somewhere. It must have been in one of the files that's included by <iostream> or <string>. It would be good practice to explicitly include the correct header file for sleep as well, but it's not strictly necessary if something is else is already including it for you.

or 'int()' function/piece of code to activate the sleep function.

I don't know what you mean by this. You already are calling the sleep function. It's right there in your code.

How do I get the sleep function to work?

What makes you think it isn't working? What results are you seeing that make you think that? You've not been clear about what problem you're seeing.
Last edited on Jun 27, 2013 at 5:10pm
Jun 28, 2013 at 10:01am
It isn't working because #include <iostream> does not include sleep. What I'm asking in short is, 'What Does?'.
Jun 28, 2013 at 10:20am
So, you mean it's not compiling? It would help if you explained your problems more clearly. It always helps to post the actual text of the errors you're getting, too.

What platform are you on? I think on Linux, it's in <unistd.h>, but I could be misremembering. I also think it sleeps for the specified number of seconds - do you really want to be sleeping for 1000 seconds?

If you're on Windows, the function is Sleep, and it the argument is in milliseconds. According to MSDN, it's in different header files for different Windows versions, so you'll have to have a look at the documentation yourself to see which one is right for your version of Windows.
Jul 4, 2013 at 11:14am
Sorry! I am using an online compiler, that I think is based upon Windows. In this case, 1000 refers to 10 seconds, does it not. In the case that it is based on Linux, that's where I am a beginner, as I have no experience with Linux whatsoever. You could say that I am a 'Die Hard Windows Fan', but that's besides the point.

I'm sorry, I am a beginner, but does anybody here understand what I mean?

Thanks anyway, everybody!
Jul 4, 2013 at 11:22am
The Windows library function is Sleep. It takes a number of milliseconds as an argument.

The Linux library function is sleep. It takes a number of seconds as an argument.

You need to first find out what platform your online compiler uses, and then use the correct function name and arguments.
Jul 4, 2013 at 11:39am
Ah! Now my problem is much closer to being solved! Thank you for your help, MikeyBoy!
Jul 4, 2013 at 1:08pm
You're welcome :)
Topic archived. No new replies allowed.