C++ string usage: compile error

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
New poster
Posts: 3
Joined: Mon Jul 09, 2007 11:48 pm

C++ string usage: compile error

Post by losvald »

Whenever I try to use std::string I always get compile error.
Here is the example:

Code: Select all

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cctype>
#include <stack>
using namespace std;
const int inf = 1000000000;
string num;   //here it says Syntax error before ; token
//... the rest of the code
I tried including many header but nothing helps, even when using std::string instead of string. What is the problem here, this works fine on every other compiler?

Krzysztof Duleba
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland

Post by Krzysztof Duleba »

You forgot the right include.
For millions of years, mankind lived just like the animals. Then something happened which unleashed the power of our imagination. We learned to talk and we learned to listen...

Experienced poster
Posts: 109
Joined: Sun Mar 11, 2007 2:55 pm
Location: SUST

Post by mmonish »

for using std:string u have to include the right header file.

Code: Select all

try using this.

Hope this helps.

New poster
Posts: 3
Joined: Mon Jul 09, 2007 11:48 pm

Post by losvald »

Thx works now.

New poster
Posts: 1
Joined: Sat Jul 28, 2007 8:47 am

Post by wuzsh »

losvald wrote:Thx works now.

Code: Select all

#include <cstring> ==> for c strings
#include <string>  ==> for c++ string class

Post Reply

Return to “C++”