Solved

can't use strings in my header file

Posted on 2007-04-07
5
195 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 25 total points
ID: 18870089
use std::string instead of string
0
 
LVL 11

Assisted Solution

by:DeepuAbrahamK
DeepuAbrahamK earned 25 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:DeepuAbrahamK
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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

623 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