|
From: Ioannis V. <no...@ho...> - 2002-11-06 00:39:00
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Jerry van Dijk
> Sent: Tuesday, November 05, 2002 12:51 AM
> To: dev...@li...
> Subject: [Dev-C++] C++ question
>
>
>
> While trying out g++ 3.2, I did the following:
>
> -----------------------------------------------------------------
> #include <vector>
> #include <string>
>
> int main(int argc, char* argv[])
> {
> // std::vector<std::string> arguments(argv[0], argv[argc]);
> std::vector<std::string> arguments;
> for (int i=0; i<argc; i++)
> arguments[i]=argv[i];
> }
> -----------------------------------------------------------------
>
> which compiles Ok, but segfaults on execution. I did a lot of
> headscratching
> but I cannot figure out why. arguments[i] evaluates to a
> string type, argv[i]
> to effectively a const char*, and string has an const char*
> constructor.
Because arguments is empty. You will either use push_back() or, you will
create initial objects using the constructor or resize().
>
> Help would be apreciated.
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
|