Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

where to find string class

0 views
Skip to first unread message

Robin

unread,
Mar 12, 2010, 3:42:27 PM3/12/10
to
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....

Thank you,
-Robin

Leigh Johnston

unread,
Mar 12, 2010, 3:49:17 PM3/12/10
to

"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;

/Leigh

Robin

unread,
Mar 12, 2010, 6:15:43 PM3/12/10
to
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?

Thanks,
-Robin

Leigh Johnston

unread,
Mar 12, 2010, 6:19:06 PM3/12/10
to
"Robin" <rob...@cnsp.com> wrote in message
news:f14b320f-9ec3-401f...@t20g2000yqe.googlegroups.com...

> 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?
>
> 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

Ian Collins

unread,
Mar 12, 2010, 6:17:44 PM3/12/10
to
On 03/13/10 12:15 PM, Robin wrote:

[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

Daniel T.

unread,
Mar 12, 2010, 6:23:53 PM3/12/10
to
Robin <rob...@cnsp.com> wrote:

> 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.

Default User

unread,
Mar 12, 2010, 6:40:20 PM3/12/10
to
Robin wrote:

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

Robin

unread,
Mar 12, 2010, 7:57:08 PM3/12/10
to

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

Ian Collins

unread,
Mar 12, 2010, 8:02:30 PM3/12/10
to
On 03/13/10 01:57 PM, Robin wrote:
> Leigh Johnston wrote:
>> "Robin"<rob...@cnsp.com> wrote in message
>> news:f14b320f-9ec3-401f...@t20g2000yqe.googlegroups.com...
>>> 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?
>>>
>>> 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;
>> }
>
> thanks for your help....I tried the code and found I didn't have
> either library, std::string or std::vector installed.

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

Robin

unread,
Mar 12, 2010, 9:25:21 PM3/12/10
to
can you point me to a web site where I can download these two headers,
though...I don't have them, they did not come with openwatcom compiler
or devc++. Thanks,
-Robin

Robin

unread,
Mar 12, 2010, 10:21:56 PM3/12/10
to

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

LR

unread,
Mar 13, 2010, 2:29:21 AM3/13/10
to
Robin wrote:


> // 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

Juha Nieminen

unread,
Mar 13, 2010, 6:00:07 AM3/13/10
to
Robin wrote:
> doesn't compile on windows 7 with the open watcom compiler at
> all....does anyone offhandedly know why

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 ---

Brian

unread,
Mar 13, 2010, 2:00:05 PM3/13/10
to

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

James Kanze

unread,
Mar 13, 2010, 7:13:03 PM3/13/10
to
On Mar 12, 11:17 pm, Ian Collins <ian-n...@hotmail.com> wrote:
> On 03/13/10 12:15 PM, Robin wrote:

[...]


> 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

0 new messages