This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Error with basic string
- From: "Ajay Bansal" <Ajay_Bansal at infosys dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Thu, 23 Jan 2003 23:49:51 +0530
- Subject: RE: Error with basic string
Ooops.. Copy-pasted wrong func defination
Correct function is..........
char *func(string a, int n)
{
a.resize(n);
return a.begin();
}
And error is
-----------------------
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 `__gnu_cxx::__normal_iterator<char*,
std::basic_string<char, std::char_traits<char>, std::allocator<char>
> >' to
`char*' in return
-----Original Message-----
From: Ajay Bansal
Sent: Thursday, January 23, 2003 11:45 PM
To: gcc-help@gcc.gnu.org
Subject: 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