This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Error with basic string


Hi All

I am trying to compile the following simple function on RH73 with gcc
3.2.1

*********string_test.cpp**************
#include <iostream>
#include <string>
using namespace std;
char * func(string a, int n)
{
	a.resize(n);
	return (char *)a.begin();
}

int main() 
{
	string a;
	char *b;
	b=func(a,5);

	return 0;
}

***************

I get the folowing error

[ajay@linux1 stl]$ g++ string_test.cpp 
string_test.cpp: In function `char* func(std::basic_string<char, 
   std::char_traits<char>, std::allocator<char> >, int)':
string_test.cpp:7: cannot convert `std::basic_string<_CharT, _Traits, 
   _Alloc>::begin() [with _CharT = char, _Traits =
std::char_traits<char>, 
   _Alloc = std::allocator<char>]()' from type `
   __gnu_cxx::__normal_iterator<char*, std::basic_string<char, 
   std::char_traits<char>, std::allocator<char> > >' to type `char*'

How to resolve this error. This program works fine on my solaris and HP
machine with their compilers (workshop on sun and aCC on HP)

I can not change the return type of func.

Regards
Ajay



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]