Thank you,
-Robin
The std::basic_string template is part of C++. std::string is an
instantiation of std::basic_string for char. For an "array" of strings use
std::vector:
std::vector<std::string> someStrings;
/Leigh
Thanks,
-Robin
#include <vector>
#include <string>
#include <iostream>
int main()
{
std::vector<std::string> someStrings;
someStrings.push_back("apples");
someStrings.push_back("oranges");
std::cout << "first string: " << someStrings[0] << std::endl;
std::cout << "second string: " << someStrings[1] << std::endl;
}
outputs:
first string: apples
second string: oranges
/Leigh
[please don't top-post]
> Leigh Johnston wrote:
>> "Robin"<rob...@cnsp.com> wrote in message
>> news:e04e5b60-2e8f-46eb...@f8g2000yqn.googlegroups.com...
>>> I am a c++ beginner and was wonder if anyone knows of where I can find
>>> a c++ string class for download that is easy to use for creating
>>> strings, arrays of strings, and manipulating strings....
>>>
>>
>> The std::basic_string template is part of C++. std::string is an
>> instantiation of std::basic_string for char. For an "array" of strings use
>> std::vector:
>>
>> std::vector<std::string> someStrings;
>>
> Can you or someone give me an example of how to include this library
> and how to use it to create strings and arrays of them?
>
You include the headers that declare the library classes and function,
you don't include a library. The linker combines your code with the
appropriate libraries at link time. Your tool should do all that for
you, so you don't have to worry about the details.
Just include <string> for strings and <vector> for vectors. Your C++
book should have made this clear.
--
Ian Collins
> Leigh Johnston wrote:
> > "Robin" <rob...@cnsp.com> wrote in message
> > news:e04e5b60-2e8f-46eb...@f8g2000yqn.googlegroups.com...
> > > I am a c++ beginner and was wonder if anyone knows of where I can find
> > > a c++ string class for download that is easy to use for creating
> > > strings, arrays of strings, and manipulating strings....
> > >
> >
> > The std::basic_string template is part of C++. std::string is an
> > instantiation of std::basic_string for char. For an "array" of strings use
> > std::vector:
> >
> > std::vector<std::string> someStrings;
>
> Can you or someone give me an example of how to include this library
> and how to use it to create strings and arrays of them?
// at the top of your .cpp file...
#include <string>
#include <vector>
And Robin, find a better book.
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.com/c++-faq-lite/how-to-post.html>
> Can you or someone give me an example of how to include this library
> and how to use it to create strings and arrays of them?
Here's one site with some information about std::string:
<http://www.cplusplus.com/reference/string/string/>
Brian
thanks for your help....I tried the code and found I didn't have
either library, std::string or std::vector installed.
Where can I find and download and install these two?
Thanks,
-Robin
They aren't libraries, they are headers. Do you have a C++ compiler
installed? They should be were the compiler knows to find them if you have.
>
> Where can I find and download and install these two?
With your compiler.
--
Ian Collins
Nevermind, I have these classes....but for some reason
// my first string
#include <iostream>
#include <string>
using namespace std;
int main () {
string a;
a = "f";
cout << a;
return 0;
}
doesn't compile on windows 7 with the open watcom compiler at
all....does anyone offhandedly know why it won't compile on windows 7
home premium using openwatcom.... Thanks
> // my first string
> #include <iostream>
> #include <string>
>
> using namespace std;
>
> int main () {
> string a;
> a = "f";
> cout << a;
> return 0;
>
> }
>
>
> doesn't compile on windows 7 with the open watcom compiler at
> all....does anyone offhandedly know why it won't compile on windows 7
> home premium using openwatcom.... Thanks
Can you say which version you are using?
What error messages you're getting?
Perhaps the last question in this faq
http://www.openwatcom.org/index.php/Open_Watcom_FAQ would be useful?
Or this http://www.openwatcom.org/index.php/Open_Watcom_STL
LR
You know, that's not a very helpful question. "Doesn't compile" tells
nothing. You have to be more specific. What does it do when you try to
compile it? Does it give an error message? Which message in particular?
--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---
flex_string, a part of the Loki library, is an excellent option.
http://loki-lib.sourceforge.net/
Brian Wood
http://webEbenezer.net
(651) 251-9384
[...]
> You include the headers that declare the library classes and
> function, you don't include a library. The linker combines
> your code with the appropriate libraries at link time. Your
> tool should do all that for you, so you don't have to worry
> about the details.
You do have to be sure that you're linking the code as a C++
program. I'm not familiar with OpenWatcom (the compiler cited
by the original poster); but, for example, with gcc, you have
to use g++ to invoke the linker if you want things to happen
automatically: using gcc or ld requires explicitly specifying
the C++ libraries.
--
James Kanze