473,757 Members | 6,899 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string class problem

can anyone tell me a solution:
i cannot use the features in standard c++ string classgh i included
the string.h file but still its not working.

Jun 25 '07
22 2621
James Kanze wrote:
>
This would be good advice IF you could realiably count on a
conformant <cstring>. In practice, you can't, and you're
probably better off for the time being still using <string.h>.

If you can't count on <cstringbeing conformant, you can't
count on much and you might as well trash the compiler.

While there are a few things (like template exporting) that
are not well implemented across the board, I fail to see
why people should live in the past in the off chance
that some oddball compiler might be so far deviant from
the standard that things like this are a concern.

Even Microsoft (not the most responsive to the standards)
has been fairly compliant for many years.
Jun 27 '07 #11
Ron Natalie wrote:
Default User wrote:
Erik Wikström wrote:

I'd like to add that none of the C++ standard headers have a .h in
them.
Not true. While deprecated, several .h headers are standard.
Nope, there are no C++ headers that have .h, deprecated or otherwise.

What there exists are the C headers that the C++ standard includes
by reference. These can be done either by their C names (such
as stdio.h) or by a not-deprecated C++ interface (cstdio).
They are still C++ standard headers.


Brian
Jun 27 '07 #12
ll
On 6 26 , 12 15 , mann_math...@ya hoo.co.in wrote:
can anyone tell me a solution:
i cannot use the features in standard c++ string classgh i included
the string.h file but still its not working.
you can use it as follow:
#include<string >
using namespace std;

or
#include<string >
std::string str;//definition

Regards
Lung

Jun 27 '07 #13
On Jun 27, 1:34 pm, Ron Natalie <r...@spamcop.n etwrote:
Default User wrote:
Erik Wikström wrote:
I'd like to add that none of the C++ standard headers have a .h in
them.
Not true. While deprecated, several .h headers are standard.
Nope, there are no C++ headers that have .h, deprecated or otherwise.
It depends on what you consider "C++ headers". They are defined
as being part of C++ by the C++ standard, and the contents of
the C++ versions aren't 100% identical to the C versions. On
the other hand, the C++ standard does make the distinction
between "C++ headers" and "C headers". So there are standard
headers in C++ (or "C++ standard headers") with a .h, but they
aren't "C++ headers" in the sense of the standard. (Except that
it doesn't make sense---if they are part of standard C++, and
the contents are not even identical to the headers in C, how can
one say that they aren't "C++ headers".)
What there exists are the C headers that the C++ standard includes
by reference. These can be done either by their C names (such
as stdio.h) or by a not-deprecated C++ interface (cstdio).
Any headers like iostream.h are not part of C++ (deprecated
or otherwise). Their vestiges of early non-standard implementations .
So which is it? The are not part of *standard* C++, but C++
existed long before it was standardized, and they are definitly
a part of traditional C++. Standard C++ is not all of C++. (To
begin with, only a lucky few have the privilege of being able to
use a standard conformant compiler in their daily work.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 28 '07 #14
On Jun 27, 1:37 pm, Ron Natalie <r...@spamcop.n etwrote:
James Kanze wrote:
This would be good advice IF you could realiably count on a
conformant <cstring>. In practice, you can't, and you're
probably better off for the time being still using <string.h>.
If you can't count on <cstringbeing conformant, you can't
count on much and you might as well trash the compiler.
In a certain sense, you can't. At least, not unless it is. In
practice, most implementations today do provide a version of
<stringwhich is more or less conformant. In practice, I've
yet to see an implementation in which e.g. <cstdlibis
conformant.

The current draft has loosened the requirements considerably in
this respect; if it is accepted in the current state, most
implementations of <cstringwill become conformant, where they
aren't today. (<cstdlibis another story; none of the
compilers I have access to include the required overloads of
atexit, for example.)
While there are a few things (like template exporting) that
are not well implemented across the board, I fail to see
why people should live in the past in the off chance
that some oddball compiler might be so far deviant from
the standard that things like this are a concern.
Perhaps because of the simple fact that very few compilers are
conformant in this respect.
Even Microsoft (not the most responsive to the standards)
has been fairly compliant for many years.
Not in VC 2005. A quick check shows that VC++ and g++ are not
conform; in both cases, <cstdlibinjec ts names which it
shouldn't into the global namespace.

Personally: these headers define a C API, much like the Posix
standard headers do. So it seems more natural and more correct
to use the C standard forms. And not even count on the few
changes C++ introduced being present. (The one that would be
most important to me, the overload of atexit, isn't present in
any of the implementations I have access to.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 28 '07 #15

James Kanze wrote in message...

/* """
(<cstdlibis another story; none of the
compilers I have access to include the required overloads of
atexit, for example.)
""" */

I'm a little in-the-fog here [1].
// -------
In <cstdlib(GCC(Mi nGW)3.3.1), after the #undefs:

namespace std {
// .....
using ::atexit;
// ..... }

In <stdlib.h>:
/* Note: This is in startup code, not imported directly from dll */
int __cdecl atexit (void (*)(void));
// -------

What 'required overloads' are you refering to?
(short answer, if you can.<GI'm just curious.)

[1] - ...still on first cup of coffee.
--
Bob R
POVrookie
Jun 28 '07 #16
On 27 Jun, 12:37, Ron Natalie <r...@spamcop.n etwrote:
James Kanze wrote:
This would be good advice IF you could realiably count on a
conformant <cstring>. In practice, you can't, and you're
probably better off for the time being still using <string.h>.

If you can't count on <cstringbeing conformant, you can't
count on much and you might as well trash the compiler.

While there are a few things (like template exporting) that
are not well implemented across the board, I fail to see
why people should live in the past in the off chance
that some oddball compiler might be so far deviant from
the standard that things like this are a concern.

Even Microsoft (not the most responsive to the standards)
has been fairly compliant for many years.
It's an example using <cstdiorather than <cstring>, but MSVS2005
(language extensions disabled) and Comeau online both compile this:

#include <cstdio>
int main()
{
printf("This should not compile.\n");
}

That's enough for me to not bother with <cxxxheaders. YMMV.

Gavin Deane

Jun 28 '07 #17
"Gavin Deane" <de*********@ho tmail.comwrote in message
news:11******** **************@ q75g2000hsh.goo glegroups.com.. .
On 27 Jun, 12:37, Ron Natalie <r...@spamcop.n etwrote:
>James Kanze wrote:
This would be good advice IF you could realiably count on a
conformant <cstring>. In practice, you can't, and you're
probably better off for the time being still using <string.h>.

If you can't count on <cstringbeing conformant, you can't
count on much and you might as well trash the compiler.

While there are a few things (like template exporting) that
are not well implemented across the board, I fail to see
why people should live in the past in the off chance
that some oddball compiler might be so far deviant from
the standard that things like this are a concern.

Even Microsoft (not the most responsive to the standards)
has been fairly compliant for many years.

It's an example using <cstdiorather than <cstring>, but MSVS2005
(language extensions disabled) and Comeau online both compile this:

#include <cstdio>
int main()
{
printf("This should not compile.\n");
}

That's enough for me to not bother with <cxxxheaders. YMMV.
Calm down. There's a difference between a compiler accepting
a program that *should* compile and one failing to compile a
program that *shouldn't* compile. And in this particular case,
the issues run even deeper. Several compiler vendors warned the
C++ committee that their rules for namespaces in <*.hvs <c*>
headers were unrealistic, but their warnings were ignored. As a
consequence, the rules of C++98 have been largely ignored, to
repay the compliment, by *most* compiler vendors, not just
Microsoft. Now guess what -- the next C++ Standard (informally
known for now as C++0X) has finally accepted the obvious and
blessed the behavior you're seeing. So this is just a transient
hiccup, not a major sin.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jun 28 '07 #18
On Jun 29, 12:40 am, "P.J. Plauger" <p...@dinkumwar e.comwrote:
"Gavin Deane" <deane_ga...@ho tmail.comwrote in message
news:11******** **************@ q75g2000hsh.goo glegroups.com.. .
On 27 Jun, 12:37, Ron Natalie <r...@spamcop.n etwrote:
James Kanze wrote:
[...]
It's an example using <cstdiorather than <cstring>, but MSVS2005
(language extensions disabled) and Comeau online both compile this:
#include <cstdio>
int main()
{
printf("This should not compile.\n");
}
That's enough for me to not bother with <cxxxheaders. YMMV.
Calm down. There's a difference between a compiler accepting
a program that *should* compile and one failing to compile a
program that *shouldn't* compile. And in this particular case,
the issues run even deeper. Several compiler vendors warned the
C++ committee that their rules for namespaces in <*.hvs <c*>
headers were unrealistic, but their warnings were ignored. As a
consequence, the rules of C++98 have been largely ignored, to
repay the compliment, by *most* compiler vendors, not just
Microsoft. Now guess what -- the next C++ Standard (informally
known for now as C++0X) has finally accepted the obvious and
blessed the behavior you're seeing. So this is just a transient
hiccup, not a major sin.
Just to make my point of view clearer: I didn't mean to (overly)
criticize the implementors with my comments. My opinion was
very much that none of the implementations were conform,
*because* the requirements of the standard weren't really
reasonable (which I really should have said explicitly). Which
means, in a very real sense, that I don't know what I can count
on in the <cxxxheaders. I knew what most implementors did,
and I rather thought that it was a reasonable compromize, but
why count on it? What if the standard adopted a different
position in the future, in its attempts to become reasonable?

As for Gavin's comment: I agree. Why bother with the new
headers if they don't provide what the standard claims to
require? There's certainly no rush; the old ones aren't going
to disappear, and my code will work just as well with them.

Now that the standard has been clarified, I'll probably
reevaluate my position. Although somewhere deep inside me, I
still don't see any real reason for the <cxxxheaders---I'm
using a legacy, C API, so why hide the fact?

(This is, of course, independant of the atexit problem. Where
the library implementor is rather at the mercy of the compiler,
and whether it implements `extern "C"' correctly.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 29 '07 #19
On Jun 28, 7:44 pm, "BobR" <removeBadB...@ worldnet.att.ne twrote:
James Kanze wrote in message...
/* """
(<cstdlibis another story; none of the
compilers I have access to include the required overloads of
atexit, for example.)
""" */
I'm a little in-the-fog here [1].
// -------
In <cstdlib(GCC(Mi nGW)3.3.1), after the #undefs:

namespace std {
// .....
using ::atexit;
// ..... }
Which, of course, isn't a legal implementation according to the
current standard (although the next release will make it one).
In <stdlib.h>:
/* Note: This is in startup code, not imported directly from dll */
int __cdecl atexit (void (*)(void));
// -------
What 'required overloads' are you refering to?
extern "C" int atexit(void (*f )(void))
extern "C++" int atexit(void (*f )(void))

Note that the standard requires this for every function in the C
library which takes a callback.

And of course, the real problem here is that the compiler isn't
conform; a header which did the above with g++ probably wouldn't
compile. (But then, g++ is just behaving like most other
implementors in this respect: implement whatever you feel like,
rather than what the standard requires.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 29 '07 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
8702
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 knowledgeable insight into this. My class Position has a string (private, public - doesn't seem to matter which), which I construct in a member function and wish to return calls from main(). However, although
19
3194
by: Mike Tyka | last post by:
Hello community, i'm fairly new to using the STL but i've been experimenting a bit with it. I tried to derive a new class say MyString from string like so: class MyString: public string{ public: MyString(){} };
13
11026
by: M | last post by:
Hi, I've searched through the previous posts and there seems to be a few examples of search and replacing all occurrances of a string with another string. I would have thought that the code below would work... string gsub(const string & sData, const string & sFrom,
32
14888
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
1
5241
by: Simon | last post by:
Hi, I have a class that does not seem to work. I cannot see the problem, and the "fix" I have found does not help me understand what the problem was I know I don't need a copy constructor but the class might grow later and I prefer having my copy constructor. This also explains why I have 2 similar function "ClearAll() and NullAll()" they might be used later in case I have pointers.
5
7244
by: Martin Jørgensen | last post by:
Hello again, Sorry to bother but I guess my C++ book isn't very good since it obviously contains errors so the program code doesn't work with g++. However I don't understand what the problem is. Last time the problem was that "using namespace std" apparently had a "link" class/object defined already. Now I get: error: no matching function for call to 'String::String(String)'
6
2205
by: tommaso.gastaldi | last post by:
Hi, does anybody know a speedy analog of IsNumeric() to check for strings/chars. I would like to check if an Object can be treated as a string before using a Cstr(), clearly avoiding the time and resource consuming Try... Catch, which in iterative processing is totally unacceptable. -tom
3
1796
by: sernamar | last post by:
Hi, I have the following base class class UnitOfMeasure { public: //... std::string& GetName() {return _uomName;}; //... protected:
9
2097
by: jerry.upstatenyguy | last post by:
I am really stuck on this. I am trying to write a string array containing a "word" and a "definition" to a class called Entry. Ultimately this will end up in another class called dictionary. No, this is not a homework assignment. In fact it was a question on my class midterm that everyone bombed. Unfortunately we never covered this in class prior to the midterm. Anyway, please help if you would be so kind. Here is what I have. I...
3
4087
by: ryan.gilfether | last post by:
I have a problem that I have been fighting for a while and haven't found a good solution for. Forgive me, but my C++ is really rusty. I have a custom config file class: class ConfigFileValue { public: operator string(); // allow this class to be typecast into a string operator char*(); // allow this class to be typecast into a char*
0
9489
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9885
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9737
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7286
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.