472,789 Members | 1,228 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 software developers and data experts.

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

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

Jul 23 '05 #1
9 2772
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.

Jul 23 '05 #2

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

Jul 23 '05 #3
"Vinu" <vi*********@yahoo.com> 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.

Jul 23 '05 #4
don't consider it as main consider it as a function whic is passing int
and a wchar_t*
ok

Jul 23 '05 #5
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*[]?

Jul 23 '05 #6
ya
compiler supports an argv of type wchar_t*[]

wchar_t internal representation is diff?

Jul 23 '05 #7
"Vinu" <vi*********@yahoo.com> 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?)

Jul 23 '05 #8
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

Jul 23 '05 #9
g++ & unix

Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Steven T. Hatton | last post by:
The short sample program listed below has some features that I find to be bad style. In particular, they fail to communicate the connection between names used in this program and the location in...
7
by: qazmlp | last post by:
void func() { // Is it by anyway possible to read the value of the first command line parameter i.e. argv here ? } int main() { func() ; // No command line arguments are passed to func(). }
4
by: Vinu | last post by:
hi How can i accept unicode char in command line. The application on Solaris Sparc expects wide characters for its processing Can you suggest standard way of doing it on Sun Solaris Sparc? We...
14
by: Hal Styli | last post by:
Is this a style thing? int main(int argc, char *argv ) or int main(int argc, char **argv ) i.e. *argv or **argv Why choose the latter?
13
by: Sokar | last post by:
I have my main function set up as int main(int argv, char *argv) so taht i can read in a variable which is passed to the program on the command line. The problem is that main calls other...
1
by: mudanoman | last post by:
Hello, I am new to c and need help with a current program I am working on. Currently, the program (code below) input is as follows: program apple.test.com 51112 What I need is...
9
by: pkirk25 | last post by:
int main(int argc, char *argv) { int z = 0; cout << *argv << endl; return z; } tester hi james outputs the letter 'j'
7
by: =?Utf-8?B?Vmlu?= | last post by:
Hi, I have a question. I created a simple executable program using Visual C++ from Visual Studio 6.0 This program is called from a script that passes in one argument. Now, my question is: ...
4
by: interec | last post by:
Hi Folks, I am writing a c++ program on redhat linux using main(int argc, wchar_t *argv). $LANG on console is set to "en_US.UTF-8". g++ compiler version is 3.4.6. Q1. what is the encoding of...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.