Solved

can't use strings in my header file

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
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 clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

821 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