Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-05-2005, 10:56 AM   #1 (permalink)
Sully
Registered User
 
Join Date: Feb 2005
Posts: 2
Sully is on a distinguished road
String question

Newbie level programmer...I've taken two C++ college course and I'm now in a data structures class. Using MSVC++ V.6.

I'm using a class that will be called ItemType and will have one member variable of type string:
Code:
#include <fstream>
#include <string>

const int MAX_ITEMS = 50;
enum RelationType  {LESS, GREATER, EQUAL};

class ItemType 
{ 
public:
  ItemType();
  RelationType ComparedTo(ItemType) const;
  void Print(std::ostream&) const;
  void Initialize(int number);
private:
  string name;
};
I've actually copied this code from our textbook where it was originally coded with a member variable of: int value; Then I am using a sorted list class that will make use of an ItemType object to create a list and manipulate the list.

Problem: When I compile the client file, I get an error that says the following:

1. c:\documents and settings\project#2a\itemtype.h(18) : error C2146: syntax error : missing ';' before identifier 'name'

2. c:\documents and settings\project#2a\itemtype.h(18) : error C2501: 'string' : missing storage-class or type specifiers

3. c:\documents and settings\project#2a\itemtype.h(18) : error C2501: 'name' : missing storage-class or type specifiers

I added the statement: using namespace std; to the header file and the errors go away, however, I believe that is not the right solution (for a reason that I am unsure of at this point). I posed this problem to my instructor and he indicated that I need to modify the envorinment variables.

If anyone here can shed light on this problem I sincerely appreciate it.

Thanks.

Sully

Last edited by redhead; 02-05-2005 at 11:34 AM. Reason: Use [ code] tags
Sully is offline   Reply With Quote
Old 02-05-2005, 11:35 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,713
redhead is on a distinguished road
have you tried:
Code:
 std::string name;
instead of the simple string decleration ??
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 02-05-2005, 01:14 PM   #3 (permalink)
Sully
Registered User
 
Join Date: Feb 2005
Posts: 2
Sully is on a distinguished road
redhead,

I used that and came up with no compile errors. I hate showing my ignorance here but I know I have quite a lot to learn in this language.

Appreciate the help.

Sully
Sully is offline   Reply With Quote
Old 02-05-2005, 05:38 PM   #4 (permalink)
ender
Code Monkey
 
ender's Avatar
 
Join Date: Mar 2003
Location: Evansville, IN
Posts: 75
ender is on a distinguished road
Send a message via AIM to ender Send a message via Yahoo to ender
If you didn't want to have to do std::string, you could put
Code:
using namespace std;
after your #includes.

-Ted
__________________
while(1) fork();
ender is offline   Reply With Quote
Old 02-05-2005, 06:10 PM   #5 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Better not though, std::whatever is better.
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help for another program Androto Standard C, C++ 54 10-15-2004 07:21 AM
From C to Java HighterDK Java 11 07-13-2004 07:15 PM
Silly Question: Adding a line break in a string JeC PHP 4 03-17-2003 10:06 AM


All times are GMT -8. The time now is 06:33 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting