[comp.lang.c++] OOPS library Strings and char*

psxgas@cs.nott.ac.uk (Alan Shepherd) (08/01/88)

Does anyone know how to use the OOPS Strings in standard C++ routines which
take char* parameters

eg. filebuf.open(char*, {input,output}) ?

The manual says that the operator const char*() should do the trick, but
this has been commented out of the code and marked 'cfront bug'.  The
replacement, operator constCharPtTy() doesn't seem to work either.  Normal
casting i.e. filebuf.open((char*) &String_name, input) compiles fine, but
doesn't perform as expected.

For the time being, I've adopted the following solution :

  filebuf.open((char*) (String_name(0,String_name.length()).ptr()),input);


This uses the substring class method ptr() which returns a const char* by
converting the string into a substring using the SubString operator()(pos,len)
.

Thanks for any help,

Alan Shepherd

krohn@u1100a.UUCP (Eric Krohn) (08/09/88)

In article <2859@robin.cs.nott.ac.uk> psxgas@nott-cs.UUCP writes:
] Does anyone know how to use the OOPS Strings in standard C++ routines which
] take char* parameters
] 
] For the time being, I've adopted the following solution :
] 
]   filebuf.open((char*) (String_name(0,String_name.length()).ptr()),input);

That's rather ugly!  I've used both of the following
	&String_name[0]
and
	str2str (String_name)

where str2str is defined as:
static const char *str2str (const char *str) { return (str); }
Both expressions have type const char *.
String_name is, of course, declared to be of type String.

-- 
--
Eric J. Krohn
krohn@ctt.ctt.bellcore.com  or  {bcr,bellcore}!u1100a!krohn
Bell Communications Research,	444 Hoes Ln,    Piscataway, NJ 08854