Solved

can't use strings in my header file

Posted on 2007-04-07
5
188 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now