GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-Sep-2007, 10:14
ftmthy412 ftmthy412 is offline
New Member
 
Join Date: Sep 2007
Posts: 8
ftmthy412 is on a distinguished road
Question

error: expected unqualified-id before ‘{’ token


Hey all

I'm compiling another short test program to experiment with string declarations, and I get this error message:
CPP / C++ / C Code:
 error: expected unqualified-id before ‘{’ token

Here's the code:
CPP / C++ / C Code:
//this is a test program using a string

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int main();
{




//tell the user to enter a sentence

cout<< "Please enter a sentence:";

//declare the variable

string USERINPUT;

//define the input

cin>> USERINPUT;

//return the sentence
cout<< "You entered: " USERINPUT endl;

return 0;

}

Does anyone know what I did wrong?
Thanks.
  #2  
Old 12-Sep-2007, 10:48
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 960
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: error: expected unqualified-id before ‘{’ token


CPP / C++ / C Code:
int main();  // <-- do not put a semi-colon here.
{
There will be an error in another statement (ok, hint: cout), but I'll let you ponder that one.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 12-Sep-2007, 11:08
ftmthy412 ftmthy412 is offline
New Member
 
Join Date: Sep 2007
Posts: 8
ftmthy412 is on a distinguished road

Re: error: expected unqualified-id before ‘{’ token


Thanks. OK, I don't get errors anymore, but maybe I'm declaring the variable wrong or something because it only prints back one word out of the sentence it was given...? But I thought "string" would hold spaces too.
  #4  
Old 12-Sep-2007, 11:32
davis
 
Posts: n/a

Re: error: expected unqualified-id before ‘{’ token


Quote:
Originally Posted by ftmthy412
Thanks. OK, I don't get errors anymore, but maybe I'm declaring the variable wrong or something because it only prints back one word out of the sentence it was given...? But I thought "string" would hold spaces too.

std::string does hold more, but cin, by default, "stops" loading data into the string when it encounters a space, tab or new line.

Check into using cin.getline to get the entire line.


:davis:
  #5  
Old 12-Sep-2007, 15:02
ftmthy412 ftmthy412 is offline
New Member
 
Join Date: Sep 2007
Posts: 8
ftmthy412 is on a distinguished road

Re: error: expected unqualified-id before ‘{’ token


Quote:
Originally Posted by davis
Check into using cin.getline to get the entire line.
:davis:

How would I do that?
  #6  
Old 12-Sep-2007, 16:49
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 960
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: error: expected unqualified-id before ‘{’ token


Like davis said:
Quote:
Originally Posted by davis
...
Check into using cin.getline to get the entire line.

:davis:
Use google to assist in finding what you need, something like this: (there were many, many other sites too)
http://www.cplusplus.com/reference/string/getline.html
EDIT: this link's example uses the string type with getline.

or, from the same site, for what davis suggested:
http://www.cplusplus.com/reference/i...m/getline.html
EDIT: this link's example uses character arrays with cin.getline
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogObservations of Iraq by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting PHP to C and I need a little help Allenport C Programming Language 4 14-Aug-2006 13:38
Need help with enums and function program rho C++ Forum 8 27-Jun-2005 19:13
Replacing N'th token in a file. kobi_hikri C Programming Language 2 24-Jun-2005 02:00
storing a token pointer as a string CoreLEx C Programming Language 1 07-Oct-2003 11:33

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:44.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.