when i compile the cpp file(cmdargs.cpp) int main(int argc, wchar_t* argv[])

Discussion in 'C++' started by Vinu, May 4, 2005.

  1. Vinu

    Vinu Guest

    Hai
    when i compile the cpp file(cmdargs.cpp) i attached the output below
    the program

    int main(int argc, wchar_t* argv[])
    {

    std::wcout<<L"Name of the Program is
    "<<*argv[0]<<std::endl;
    std::wcout<<L" Argument Count "<<argc-1<<std::endl;
    for(int args=1;args<argc;args++)
    {
    std::wcout<<L"Argument "<<args<<" is "<<
    *(argv[args])<<std::endl;
    }
    return 0;
    }


    output :
    ~~~~~~~~~~~~~~
    Name of the Program is

    -->

    -->

    -->

    -->

    #include<iostream>
    #include <stdlib.h>
    int main(int argc, wchar_t* argv[])
    {
    std::cout<<"Name of the Program is
    "<<*argv[0]<<std::endl;
    std::cout<<" Argument Count "<<argc-1<<std::endl;
    for(int args=1;args<argc;args++)
    {
    std::cout<<"Argument "<<args<<" is "<<
    *(argv[args])<<std::endl;
    }
    return 0;
    }


    cmdargs asd fgh jkl

    output :
    ~~~~~~~~~~~~~~

    Name of the Program is 1668113505
    Argument Count 3
    Argument 1 is 1634952192
    Argument 2 is 1718052864
    Argument 3 is 1785424896

    -->

    -->

    -->

    -->
    here i got some nos but i want the strings how i can print the
    values..plz help he
    Thanks in advance
    Vinu, May 4, 2005
    #1
    1. Advertising

  2. Vinu

    Andre Kostur Guest

    "Vinu" <> wrote in news:1115210388.421215.119270
    @z14g2000cwz.googlegroups.com:

    > Hai
    > when i compile the cpp file(cmdargs.cpp) i attached the output below
    > the program
    >
    > int main(int argc, wchar_t* argv[])


    Bzzt. Non-standard main. You probably want:

    int main(int argc, char * argv[])

    make appropriate changes throughout your application to follow suit.
    Andre Kostur, May 4, 2005
    #2
    1. Advertising

  3. Vinu

    Rolf Magnus Guest

    Vinu wrote:

    > Hai
    > when i compile the cpp file(cmdargs.cpp) i attached the output below
    > the program
    >
    > int main(int argc, wchar_t* argv[])
    > {
    >
    > std::wcout<<L"Name of the Program is
    > "<<*argv[0]<<std::endl;
    > std::wcout<<L" Argument Count "<<argc-1<<std::endl;
    > for(int args=1;args<argc;args++)
    > {
    > std::wcout<<L"Argument "<<args<<" is "<<
    > *(argv[args])<<std::endl;
    > }
    > return 0;
    > }
    >
    >
    > output :
    > ~~~~~~~~~~~~~~
    > Name of the Program is
    >
    > -->
    >
    > -->
    >
    > -->
    >
    > -->
    >
    > #include<iostream>
    > #include <stdlib.h>
    > int main(int argc, wchar_t* argv[])


    Does your implementation support that signature for main? Standard C++
    guarantees only

    int main()
    and
    int main(int argc, char* argv[])

    .. Any other variants would be implementation-defined.

    > {
    > std::cout<<"Name of the Program is
    > "<<*argv[0]<<std::endl;


    If you use wide characters, use a wide stream. And *argv[0] is a single
    character.

    > std::cout<<" Argument Count "<<argc-1<<std::endl;
    > for(int args=1;args<argc;args++)
    > {
    > std::cout<<"Argument "<<args<<" is "<<
    > *(argv[args])<<std::endl;
    > }
    > return 0;
    > }
    >
    >
    > cmdargs asd fgh jkl
    >
    > output :
    > ~~~~~~~~~~~~~~
    >
    > Name of the Program is 1668113505


    When sending a wchar_t to a char based stream, it is printed as an integer,
    not as a character.
    Rolf Magnus, May 4, 2005
    #3
  4. Vinu

    Vinu Guest

    Re: when i compile the cpp file(cmdargs.cpp) int main(int argc, wchar_t* argv[])

    Hai Rolf Magnus

    the real problem is when i try ti access it give Bus Error (Core Dump)
    i don't no why? when i try to access the varible argv[1] or
    argv[argc-1] anything it gives the Bus Error
    Thanks
    Vinu, May 4, 2005
    #4
  5. Vinu

    Vinu Guest

    Re: when i compile the cpp file(cmdargs.cpp) int main(int argc, wchar_t* argv[])

    don't consider it as main consider it as a function whic is passing int
    and a wchar_t*
    ok
    Vinu, May 4, 2005
    #5
  6. Vinu

    Rolf Magnus Guest

    Re: when i compile the cpp file(cmdargs.cpp) int main(int argc, wchar_t* argv[])

    Vinu wrote:

    >
    > Hai Rolf Magnus
    >
    > the real problem is when i try ti access it give Bus Error (Core Dump)
    > i don't no why? when i try to access the varible argv[1] or
    > argv[argc-1] anything it gives the Bus Error


    So I ask you again: Does your compiler documentation explicitly say that it
    supports an argv of type wchar_t*[]?
    Rolf Magnus, May 4, 2005
    #6
  7. Vinu

    Vinu Guest

    Re: when i compile the cpp file(cmdargs.cpp) int main(int argc, wchar_t* argv[])

    ya
    compiler supports an argv of type wchar_t*[]

    wchar_t internal representation is diff?
    Vinu, May 4, 2005
    #7
  8. Vinu

    Andre Kostur Guest

    Re: when i compile the cpp file(cmdargs.cpp) int main(int argc, wchar_t* argv[])

    "Vinu" <> wrote in news:1115214575.056647.316190
    @f14g2000cwb.googlegroups.com:

    > ya
    > compiler supports an argv of type wchar_t*[]
    >
    > wchar_t internal representation is diff?
    >
    >


    Have you checked your compiler's documentation on the acceptable forms of
    main(), or are you assuming that since is compiles, it's supported? (What
    is your compiler and platform?)
    Andre Kostur, May 4, 2005
    #8
  9. Vinu

    __PPS__ Guest

    Re: when i compile the cpp file(cmdargs.cpp) int main(int argc, wchar_t* argv[])

    use int main(int argc, char * argv[]) and cout
    even if you use wcout everything is still converted to chars before
    printing. Try to verify this with wchar_t based ofstream and see if
    your output file contains wide chars or not.
    Wasn't you the one who asked about command arguments classes?
    http://boost.org/doc/html/program_options.html is a really good
    alternative. Use it, don't try to envent yours own
    __PPS__, May 4, 2005
    #9
  10. Vinu

    Vinu Guest

    Re: when i compile the cpp file(cmdargs.cpp) int main(int argc, wchar_t* argv[])

    g++ & unix
    Vinu, May 5, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vinu
    Replies:
    4
    Views:
    4,781
    Ron Natalie
    May 10, 2005
  2. Hal Styli
    Replies:
    14
    Views:
    1,612
    Old Wolf
    Jan 20, 2004
  3. Replies:
    4
    Views:
    2,074
  4. significantBit

    int main(int argc, const char * argv[]) ??

    significantBit, Apr 9, 2008, in forum: C Programming
    Replies:
    2
    Views:
    1,694
    John Bode
    Apr 9, 2008
  5. mlt
    Replies:
    4
    Views:
    669
    James Kanze
    Jun 9, 2009
Loading...

Share This Page