Compile Error calling string::clear()

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

Moderator: Board moderators

Post Reply
Lebedenco
New poster
Posts: 5
Joined: Mon Aug 23, 2004 6:55 am

Compile Error calling string::clear()

Post by Lebedenco »

this code gets Compile Error on the Judge though it compiles
ok in my box (Mandrake Linux 2.6.3/gcc-3.3.2), why?:

#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <cassert>

using namespace std;

string a;
int main()
{
a.clear();
return 0;
}

am I missing something?
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim »

Hi, I submitted your code to the site

acm.zju.edu.cn and it compiles fine with their C++ compiler. I guess it is a prblem with the UVA compiler.

The line that causes sytax error is a.clear();

VC++ 6.0 is also unable to compile it.

I guess you have to do without this method. :-?
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba »

In g++ 2.95, which is used by OJ, there is no clear method in string class. However, you can always assign an empty string instead and it should work the same way:
[cpp]a = ""; [/cpp]
Post Reply

Return to “C++”