Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

can't use strings in my header file

Posted on 2007-04-07
5
Medium Priority
?
198 Views
Last Modified: 2010-04-01
can't use strings in my class header file , if a try adding a string as private or public compiler generates some wierd error. using visual studio 2005.
#include <string>    

class Song
{
public:
            char* Get_Playing_Time();

          bool Equals(Song);
          Song(); // constructor
          Song(char * titlein, char* artist,char*album,Categorys cat,int min, int secs);
private :
      char temp[40];
string test;   // errors on this line
};
0
Comment
Question by:pele4483
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 100 total points
ID: 18870089
use std::string instead of string
0
 
LVL 11

Assisted Solution

by:Deepu Abraham
Deepu Abraham earned 100 total points
ID: 18870103
While using  add using namespace std;

#include <string>
using namespace std;

then you can use
string test; rather than std::string test; which is an alternative as suggested by Infinity
Best Regards,
DeepuAbrahamK
0
 
LVL 11

Expert Comment

by:Deepu Abraham
ID: 18870107
What I mean is while using stl string header
0
 

Author Comment

by:pele4483
ID: 18870112
I KEEP FORGETTING ABOUT NAMESPACE
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 18870154
>> string test; rather than std::string test;

There's 3 ways to do this :

1) std::string

2) using std::string;
    string

3) using namespace std;
    string

in order or preference. The problem with the last option is that the whole namespace is loaded which can add a lot of unnecessary code to your executable.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question