If I want to declare a function in a header file that returns a
string, I always get an error (something complaining about
a syntax error before an ')').
I have declared:
#ifndef MYHEADER_H
#define MYHEADER_H
string function(int day, int month, int year);
#endif
But then I get always an error from the compiler.
If I change this to
#ifndef MYHEADER_H
#define MYHEADER_H
const char* function(int day, int month, int year);
#endif
I get no error.
But the problem then is, since I use an std::ostringstream oss in
the definition, I have to write "ugly" things like
return oss.str().c_str();
Is there a way to bypass this ? 2 1520
C@limero wrote: If I want to declare a function in a header file that returns a string, I always get an error (something complaining about a syntax error before an ')').
I have declared: #ifndef MYHEADER_H #define MYHEADER_H
string function(int day, int month, int year);
'string' is a typedef declared in <string> header. You need to include
that header before using 'string'. And use 'std::string' because the
name 'string' (the typedef) is declared in the 'std' namespace. So, the
line above should be replaced with two:
#include <string>
std::string function(int day, int month, int year); #endif But then I get always an error from the compiler.
If I change this to
#ifndef MYHEADER_H #define MYHEADER_H
const char* function(int day, int month, int year);
#endif
I get no error.
But the problem then is, since I use an std::ostringstream oss in the definition, I have to write "ugly" things like
return oss.str().c_str();
Is there a way to bypass this ?
No, there is no way to bypass it. It has to be resolved.
V
C@limero wrote: If I want to declare a function in a header file that returns a string, I always get an error (something complaining about a syntax error before an ')').
I have declared: #ifndef MYHEADER_H #define MYHEADER_H
#include <string>
std::string function(int day, int month, int year);
#endif
string is not a built-in type; it is a class, declared in header
<string>, and in namespace std.
--
Mike Smith This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Derek Hart |
last post by:
I wish to execute code from a string. The string will have a function name,
which will return a string:
Dim a as string
a = "MyFunctionName(param1, param2)"
I have seen a ton of people...
|
by: David Carter-Hitchin |
last post by:
Hi,
I'm not very experienced with c++ so I'm sure this is
something obvious that is easily solved, but for the life
of me I can't seem to figure it out. I'd be very grateful
for some...
|
by: Neil Schemenauer |
last post by:
The title is perhaps a little too grandiose but it's the best I
could think of. The change is really not large. Personally, I
would be happy enough if only %s was changed and the built-in was...
|
by: songkv |
last post by:
Hi,
I am trying to reassign an array of char to a string literal by
calling a function.
In the function I use pointer-to-pointer since I want to reassign the
"string array pointer" to the string...
|
by: Simon Schaap |
last post by:
Hello,
I have encountered a strange problem and I hope you can help me to
understand it. What I want to do is to pass an array of chars to a
function that will split it up (on every location where...
| |
by: tshad |
last post by:
The error I am getting is:
*******************************************************************
Exception Details: System.InvalidCastException: Cast from type 'DBNull' to
type 'String' is not...
|
by: Ed Jay |
last post by:
<disclaimer>js newbie</disclaimer>
My page has a form comprised of several radio buttons. I want to poll the
buttons to determine which button was selected and convert its value to a
string. I...
|
by: karthi |
last post by:
hi,
I need user defined function that converts string to float in c.
since the library function atof and strtod occupies large space in
my processor memory I can't use it in my code.
regards,...
|
by: simon |
last post by:
hi,
I would like to separate my javascript completely from my xhtml. in the
end there should be only
<script type="text/javascript" src="javalib.js"></script>
in the head-tag to my javascript....
|
by: jacob navia |
last post by:
Abstract:
Continuing the discussion about abstract data types, in this
discussion group, a string collection data type is presented,
patterned after the collection in C# and similar languages...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |