Page 1 of 1

Compile Error calling string::clear()

Posted: Mon Aug 23, 2004 7:05 am
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?

Posted: Mon Aug 23, 2004 11:26 am
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. :-?

Posted: Mon Aug 23, 2004 1:50 pm
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]