473,662 Members | 2,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++: String data type

Hi,

Which system header file do I unclude in order to use the new string data
type?
KJ
Jul 19 '05 #1
8 8188
In article <3f********@new s.iprimus.com.a u>,
Newsnet Customer <ni********@ipr imus.com.au> wrote:

2) I assume system header files provides implementations unlike user-defined
header files, which are just interfaces.


No, the system header files are generally just interfaces also. An
exception may be the header files that declare template classes, because
many or most compilers don't support separate compilation of templates.

The implementations are usually in a compiled library file that your
compiler automatically links to your compiled code.

--
Jon Bell <jt*******@pres by.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
Jul 19 '05 #2
Newsnet Customer <ni********@ipr imus.com.au> wrote in message
news:3f******** @news.iprimus.c om.au...
2) I assume system header files provides implementations unlike user-defined header files, which are just interfaces.
That's not a question. As an assumption, it's incorrect. For a start, in
the statement '#include <string>', the word 'string' is not a filename.
The necessary declarations, etc., may or may not be stored in a file.

if string is not a filename then what file is it actually including in

this case? an object string?


The name of the *header* is <string>. The statement:

#include <string>

Is simply required to cause the compiler to provide
all declarations the language specifies it must, at
the scope where the #include directive appears.

A compiler is free to provide these delcarations any
way at all, e.g. via a file, 'hard coded' into the
compiler, or any other way at all. It's very common
for standard headers to be represented with files,
but not at all required.

-Mike

Jul 19 '05 #3

"Mike Wahler" <mk******@mkwah ler.net> wrote in message news:5tq2b.2599

A compiler is free to provide these delcarations any
way at all, e.g. via a file, 'hard coded' into the
compiler, or any other way at all. It's very common
for standard headers to be represented with files,
but not at all required.


Not exactly right. The section header for #include
says "SOURCE FILE INCLUSION." The input units of C++ programs
are defined as SOURCE FILES in the standard. Of course, the C++
notion of source file may be different than what any particular
operating system's idea of a file is. As far as C++ is concerned
a source file is just a stream of implentation defined characters
that subsequently get processed into the source character set and then
into tokens.

Using a system that just uses a database of declarations does not meet
the C++ model (as those who were unfortunate enough to use IBM's attempt
at doing C++ that way found out).
Jul 19 '05 #4
"Newsnet Customer" <ni********@ipr imus.com.au> wrote in message news:<3f******* *@news.iprimus. com.au>...
2) I assume system header files provides implementations unlike user-defined header files, which are just interfaces.


That's not a question. As an assumption, it's incorrect. For a start, in
the statement '#include <string>', the word 'string' is not a filename.
The necessary declarations, etc., may or may not be stored in a file.

if string is not a filename then what file is it actually including in this
case? an object string?


Or a precompiled version that does exactly what the file would have done.
Or any other representation that makes the implementation behave as if
a file containg the definitions was included.

HTH,
--
Michiel Salters
Jul 19 '05 #5
Buster Copley <bu****@none.co m> wrote in message news:<bi******* **@news8.svr.po l.co.uk>...
0Newsnet Customer wrote: ,snip>
2) I assume system header files provides implementations unlike user-defined
header files, which are just interfaces.

That said, in many cases there will be a header file called 'string'.
And because separate compilation of templates is so tricky, the chances
are most of the implementation will be available just from including the
appropriate header. User header files may also include templates and
inline functions.


<string> is special, because in 99,x% of the cases it is instantiated on
either char or wchar_t, so for these two cases an implementation may very
have a separation of interface and implementation. In addition, this can
be achieved in non-portable ways, because the <string> implementation
is a compiler-specific header.

Regards,
--
Michiel Salters
Jul 19 '05 #6
Newsnet Customer wrote:

Right, so your saying that by including:

#include <string>

the compiler's preprocessor will include the contents of the <string> header
file into the source, then compile the entire source file, and then link it
with whatever file it neeeds (in this case, string.cpp). Is this what you
mean?


It is very unlikely that this is what happens. Looking at it abstractly,
the implementation may not include a file called 'string'. It may not
have such a file at all. It's possible that it uses some magic to
replace the #include directive with the right stuff. It's also possible
that it doesn't do anything except set some kind of flag in the
compiler. "Header file" is not the right term, since it may or may not
be an actual file. The term is simply "header".

In most real implementations , 'string' is the name of a real file, and
the contents of that file are inserted into the source file at the point
of the #include directive. However, it's extremely unlikely that there
would be a 'string.cpp' file that the compiler would link in, for
several reasons.

First, compiler libraries are usually .lib or .obj files, and they
usually don't have one for every header. So it would be more likely to
have something like cppstd.lib that contains all or most of the standard
library (except for templates).

Second, std::string is a specialization of a template
(std::basic_str ing), and templates cannot be separately compiled in most
implementations . So 'string.cpp' wouldn't work. It's more likely that
the entire implementation of the basic_string template is in the
<string> header.

But basically you are asking hypothetical questions that don't have any
single answer and don't affect language usage anyway. So why bother
worrying about them?

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #7
> 2) I assume system header files provides implementations unlike

user-defined
> header files, which are just interfaces.

That's not a question. As an assumption, it's incorrect. For a start, in the statement '#include <string>', the word 'string' is not a filename. The necessary declarations, etc., may or may not be stored in a file.

if string is not a filename then what file is it actually including in

this
case? an object string?


The name of the *header* is <string>. The statement:

#include <string>

Is simply required to cause the compiler to provide
all declarations the language specifies it must, at
the scope where the #include directive appears.

A compiler is free to provide these delcarations any
way at all, e.g. via a file, 'hard coded' into the
compiler, or any other way at all. It's very common
for standard headers to be represented with files,
but not at all required.


I asummed that if the header does not have an extension associated with it
then it's not a file, which leaves me thinking what <string> represents. I
don't think you have exactly told me that, but it appears that it could be
'hard-coded' into the compiler.
kdf


Jul 19 '05 #8
On Tue, 26 Aug 2003 16:24:03 +0930,
Newsnet Customer <ni********@ipr imus.com.au> wrote:
> > > 2) I assume system header files provides implementations unlike
> user-defined
> > > header files, which are just interfaces.
> >
> > That's not a question. As an assumption, it's incorrect. For a start, in > > the statement '#include <string>', the word 'string' is not a filename. > > The necessary declarations, etc., may or may not be stored in a file.
>
>
> if string is not a filename then what file is it actually including in

this
> case? an object string?


The name of the *header* is <string>. The statement:

#include <string>

Is simply required to cause the compiler to provide
all declarations the language specifies it must, at
the scope where the #include directive appears.

A compiler is free to provide these delcarations any
way at all, e.g. via a file, 'hard coded' into the
compiler, or any other way at all. It's very common
for standard headers to be represented with files,
but not at all required.


I asummed that if the header does not have an extension associated with it
then it's not a file, which leaves me thinking what <string> represents. I
don't think you have exactly told me that, but it appears that it could be
'hard-coded' into the compiler.


Your assumption is incorrect. The header could be implemented as a file,
or it could just set a flag in the compiler, or whatever.

As a counter example to your assumption:

$ ls -l /gnu/usr/include/g++-3/string
-rw-rw-r-- 1 bin bin 238 Nov 18 1999 /gnu/usr/include/g++-3/string

That compiler/library combination implementation uses a file named 'string' to
perform #include <string>.

--
Sam Holden

Jul 19 '05 #9

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

Similar topics

4
9087
by: Carl Youngblood | last post by:
I imagine this subject has probably been brought up numerous times. Forgive me for bringing it up again. I was googling through old posts on this newsgroup about it and found a good suggestion on how to add functionality to the string class. Rather than trying to inherit from the string class, the author was suggesting wrapping the string class in another class, like so: >Right !!!, we should not derive from string, but we should wrap...
1
1836
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 not added. Please comment. Neil PEP: 349 Title: Generalised String Coercion
1
4136
by: dpakpaul | last post by:
Hi, I have an XSD schema where I have attributes that are declared to contain non string values such as integers etc. Take for example, this declaration - <xs:attribute name="IsThisTrue" type="xs:boolean" /> Now, I want to write or modify an XML document using the DOM API (using C#) where this attribute will be given a boolean value. Then the resulting XML document will be validated against the schema
2
1917
by: jez123456 | last post by:
Hi I'm attempting to pass a string into another string but I get an error This code work ok jro.CompactDatabase(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Compact.mdb", @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\tempdb.mdb;Jet OLEDB:Engine Type=5"); However when I declare a string and try to pass that I get an error
6
5430
by: tshad | last post by:
The error I am getting is: ******************************************************************* Exception Details: System.InvalidCastException: Cast from type 'DBNull' to type 'String' is not valid. Source Error: Line 144: firstName.text = ClientReader("firstName") Line 145: lastName.text = ClientReader("lastName")
20
3696
by: MLH | last post by:
120 MyString = "How many copies of each letter do you need?" 150 MyVariant = InputBox(MyString, "How Many?", "3") If MyVariant = "2" Then MsgBox "MyVariant equals the string '2'" If MyVariant = 2 Then MsgBox "MyVariant also equals the value 2" 160 If MyVariant = "" Then HowManyCopies = 1 170 If Not IsNumeric(MyVariant) Then HowManyCopies = 1 MsgBox "OK. HowManyCopies has a value of " & CStr(HowManyCopies) 180 For i =...
5
2868
by: Barry | last post by:
Hello, In VS2003, I tried using an enum and setting it into a field in a datarow. It seems as if the datatype of the field in the row determined what went into the field. If the datatype was string, then the name of the enum item went into the field, but if the datatype was integer, then the integer value of the enum was stored. Is this expected behaviour? I couldn't find anything while searching for answers.
29
4247
by: zoltan | last post by:
Hi, The scenario is like this : struct ns_rr { const u_char* rdata; }; The rdata field contains some fields such as :
14
4320
by: Scott M. | last post by:
Ok, this is driving me nuts... I am using VS.NET 2003 and trying to take an item out of a row in a loosely-typed dataset and place it in a label as a currency. As it is now, I am getting my unformatted data values (as decimals) just fine, so I know there's not a problem with the data retrieval, just the formatting. I have read that this would work: lblPrice.Text = prodRow.ToString("C");
3
5088
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 (Java). It stores character strings, and resizes itself to accommodate new strings when needed. Interface: ----------
0
8435
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
8768
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
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...
0
7368
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
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
5655
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
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1754
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.