simple C++ string doubt 
Author Message
 simple C++ string doubt

Okie

am working on a non-MFC project and need an array of strings

I am doing this now
I want to know if it is okay?

char **banlist; /* global */

 banlist = new char*[100];
 int i;
 for(i=0;i<100;i++)
  banlist[i]= new char[200];

Thus I get 100 strings of 200 chars each

Now my question is this. is this OK?
or is there any better method for a non-MFC project [I dont know anything
about STL else might have used one of the STL string classes :-( ]

thanks
Nish



Sat, 03 Jan 2004 14:16:31 GMT  
 simple C++ string doubt

Quote:

> char **banlist; /* global */

>  banlist = new char*[100];
>  int i;
>  for(i=0;i<100;i++)
>   banlist[i]= new char[200];

use vector and string:
couple of examples...

#include<vector>
#include<string>

using std::vector;
using std::string;

void method()
{
vector<string> banlist(100);

int i;
for(i = 0; i < 100; i++)
{
        banlist[i]= "something";

Quote:
}
}

or

void method2()
{
vector<string> banlist();

int i;
for(i = 0; i < 100; i++)
{
        banlist.push_back("something");

Quote:
}
}

--




Sat, 03 Jan 2004 15:42:30 GMT  
 simple C++ string doubt
Thanks
that looks so cool
didnt know STL was that simple to use
But will my exe be stand-alone?
do I have to ship some extra DLLs for the STL functions?
and what are the LIBs I gotta link with?

Nish


Quote:
> use vector and string:
> couple of examples...

> #include<vector>
> #include<string>

> using std::vector;
> using std::string;

> void method()
> {
> vector<string> banlist(100);

> int i;
> for(i = 0; i < 100; i++)
> {
> banlist[i]= "something";
> }
> }

> or

> void method2()
> {
> vector<string> banlist();

> int i;
> for(i = 0; i < 100; i++)
> {
> banlist.push_back("something");
> }
> }

> --





Sat, 03 Jan 2004 15:50:23 GMT  
 simple C++ string doubt

Quote:

> Thanks
> that looks so cool
> didnt know STL was that simple to use
> But will my exe be stand-alone?
> do I have to ship some extra DLLs for the STL functions?
> and what are the LIBs I gotta link with?

Yes it is stand-alone.

--




Sat, 03 Jan 2004 15:51:54 GMT  
 simple C++ string doubt
by the way I gave this and got dozens of warnings that makeno sense
it compiles though :-)

vector<string> banlist1(100);
 int j;
 for(j=0;j<100;j++)
  banlist1[j]="hello world";

:-)))

Nish

I give the warnings below:-

d:\program files\microsoft visual studio\vc98\include\vector(48) : warning
C4786:
V

$

identifier was truncated to '255' characters in the browser information
        d:\snoopy\filters.cpp(96) : see reference to class template
instantiation 'std::vector<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >,class
std::allocator<class std::basic_string<char,struct std::char
_traits<char>,class std::allocator<char> > > >' being compiled
d:\program files\microsoft visual studio\vc98\include\vector(61) : warning
C4786:
V

$

identifier was truncated to '255' characters in the browser information
        d:\snoopy\filters.cpp(96) : see reference to class template
instantiation 'std::vector<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >,class
std::allocator<class std::basic_string<char,struct std::char
_traits<char>,class std::allocator<char> > > >' being compiled
d:\program files\microsoft visual studio\vc98\include\vector(103) : warning
C4786:
s


characters in the browser information
        d:\snoopy\filters.cpp(96) : see reference to class template
instantiation 'std::vector<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >,class
std::allocator<class std::basic_string<char,struct std::char
_traits<char>,class std::allocator<char> > > >' being compiled
d:\program files\microsoft visual studio\vc98\include\vector(105) : warning
C4786:
s


characters in the browser information
        d:\snoopy\filters.cpp(96) : see reference to class template
instantiation 'std::vector<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >,class
std::allocator<class std::basic_string<char,struct std::char
_traits<char>,class std::allocator<char> > > >' being compiled
d:\program files\microsoft visual studio\vc98\include\vector(107) : warning
C4786:


characters in the browser information
        d:\snoopy\filters.cpp(96) : see reference to class template
instantiation 'std::vector<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >,class
std::allocator<class std::basic_string<char,struct std::char
_traits<char>,class std::allocator<char> > > >' being compiled
d:\program files\microsoft visual studio\vc98\include\vector(108) : warning
C4786:


characters in the browser information
        d:\snoopy\filters.cpp(96) : see reference to class template
instantiation 'std::vector<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >,class
std::allocator<class std::basic_string<char,struct std::char
_traits<char>,class std::allocator<char> > > >' being compiled
d:\snoopy\filters.cpp(164) : warning C4786:
'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::al
locator<char> > const
*,std::basic_string<char,std::char_traits<char>,std::allocator<char>

Quote:
>,std::basic_string<char,std::char_tra

its<char>,std::allocator<char> > const
&,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const
*,int>' : identifier was truncated to '255' characters in the debug
information
d:\snoopy\filters.cpp(164) : warning C4786:
'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::al
locator<char> >
*,std::basic_string<char,std::char_traits<char>,std::allocator<char>
Quote:
>,std::basic_string<char,std::char_traits<ch

ar>,std::allocator<char> >
&,std::basic_string<char,std::char_traits<char>,std::allocator<char> >
*,int>' : identifier was truncated to '255' characters in the debug
information
d:\program files\microsoft visual studio\vc98\include\vector(47) : warning
C4786:
'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<ch
ar>
Quote:
>,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocato

r<char> > >

Quote:
>::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocato

r<char> > > >' : identifier was truncated to '255' characters in the debug
information
d:\program files\microsoft visual studio\vc98\include\vector(60) : warning
C4786:
'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<ch
ar>
Quote:
>,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocato

r<char> > >

Quote:
>::~vector<std::basic_string<char,std::char_traits<char>,std::allocator<char

>,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocato

r<char> > > >' : identifier was truncated to '255' characters in the debug
information
Linking...
Creating browse info file...


Quote:

> > char **banlist; /* global */

> >  banlist = new char*[100];
> >  int i;
> >  for(i=0;i<100;i++)
> >   banlist[i]= new char[200];

> use vector and string:
> couple of examples...

> #include<vector>
> #include<string>

> using std::vector;
> using std::string;

> void method()
> {
> vector<string> banlist(100);

> int i;
> for(i = 0; i < 100; i++)
> {
> banlist[i]= "something";
> }
> }

> or

> void method2()
> {
> vector<string> banlist();

> int i;
> for(i = 0; i < 100; i++)
> {
> banlist.push_back("something");
> }
> }

> --





Sat, 03 Jan 2004 15:58:33 GMT  
 simple C++ string doubt

try:

Quote:
> std::vector<std::string> banlist1(100);
>  int j;
>  for(j=0;j<100;j++)
>   banlist1[j]="hello world";

It can help, but I am not sure. You can also #include <cstdlib> or
<cstdlib.h>

--



Sat, 03 Jan 2004 16:13:31 GMT  
 simple C++ string doubt

Quote:

> by the way I gave this and got dozens of warnings that makeno sense
> it compiles though :-)

This warning is really just saying that the de{*filter*} can't cope with the
enormous symbols that are sometimes generated when you use the STL.
They have no relevance to the correctness of your program.  You can
disable the warning like this:

    #pragma warning( disable : 4786 )
    #include <list>      
    #pragma warning( default : 4786 )

--
Regards,


Systems and Processing Group,       Tel: +44-20-8420-3523
Sensor Systems Division,            Fax: +44-20-8420-3960
BAE SYSTEMS Avionics Limited,
The Grove, Warren Lane,
Stanmore, Middlesex.
HA7 4LY, England.

http://www.*-*-*.com/



Sat, 03 Jan 2004 16:40:56 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. microsoft visual studio - simple doubt

2. Doubt using Simple Object

3. Doubt While using Simple Object

4. simple doubt-dll

5. Simple doubt-Dll

6. Can u help me?I've a simple doubt in accessing data from VC++

7. Simple Doubt on Mouse Event Capture

8. Some simple STL doubts.

9. Converting from Variant to Simple String in C++ COM

10. simplest questions about character and string in C++

11. Simple string question (new to C++)

12. Doubt about allocation of space of string

 

 
Powered by phpBB® Forum Software