By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,345 Members | 1,667 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,345 IT Pros & Developers. It's quick & easy.

main(int arc, char *argv[])

P: n/a
int main(int argc, char *argv[])
{
int z = 0;

cout << *argv[2] << endl;
return z;
}

tester hi james outputs the letter 'j'

How can I get ti to outout the whole word?

Nov 13 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
pkirk25 wrote:
int main(int argc, char *argv[])
{
int z = 0;

cout << *argv[2] << endl;
return z;
}

tester hi james outputs the letter 'j'
This is not chat; please edit typos in your lines!
How can I get ti to outout the whole word?
Take out the *.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Nov 13 '06 #2

P: n/a
VJ
pkirk25 wrote:
int main(int argc, char *argv[])
{
int z = 0;

cout << *argv[2] << endl;
return z;
}

tester hi james outputs the letter 'j'

How can I get ti to outout the whole word?
Like this:
#include <iostream>
int main(int argc, char *argv[])
{
std::string str( argv[2] );
std::cout << str << std::endl;
}
Nov 13 '06 #3

P: n/a
pkirk25 wrote:
int main(int argc, char *argv[])
{
int z = 0;

cout << *argv[2] << endl;
Neither 'cout' nor 'endl' are defined. Did you forget to include
a proper header? BTW, your program has undefined behaviour if
the number of arguments is less than 3.
return z;
}

tester hi james outputs the letter 'j'

How can I get ti to outout the whole word?
Drop the asterisk in the output statement.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 13 '06 #4

P: n/a
VJ wrote:
pkirk25 wrote:
>int main(int argc, char *argv[])
{
int z = 0;

cout << *argv[2] << endl;
return z;
}

tester hi james outputs the letter 'j'

How can I get ti to outout the whole word?

Like this:
#include <iostream>
int main(int argc, char *argv[])
{
std::string str( argv[2] );
'std::string' is undefined.
std::cout << str << std::endl;
And why do you need the 'str' anyway? Couldn't you just do

std::cout << argv[2] << std::endl;

?
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 13 '06 #5

P: n/a
Sorry for my awful spelling in original post.

Many thanks for pointing out that removing the * fixed my problem.

As you probably guessed, tester was written just to post this question
rather than bore you with extra variables from the program where I need
to pass arguments.

Nov 13 '06 #6

P: n/a
Victor Bazarov:
And why do you need the 'str' anyway? Couldn't you just do

std::cout << argv[2] << std::endl;

There is a trend currently propogating whereby C++ programmers try to make
their programs as inefficient as possible, for sake of appearing to use safe
features. This extends to the use of "vector" when all that was needed was a
simple array.

--

Frederick Gotham
Nov 13 '06 #7

P: n/a
VJ
Victor Bazarov wrote:
VJ wrote:
>>
#include <iostream>
int main(int argc, char *argv[])
{
std::string str( argv[2] );


'std::string' is undefined.
Forgot to
#include <string>
but my program compiled. It is probably included in the iostream (at
least in the library I am using)
>
> std::cout << str << std::endl;


And why do you need the 'str' anyway? Couldn't you just do

std::cout << argv[2] << std::endl;

?
You could :)
Thanks
Nov 14 '06 #8

P: n/a
VJ wrote:
Victor Bazarov wrote:
>VJ wrote:
>>>
#include <iostream>
int main(int argc, char *argv[])
{
std::string str( argv[2] );


'std::string' is undefined.

Forgot to
#include <string>
but my program compiled. It is probably included in the iostream (at
least in the library I am using)
But you shouldn't rely on that.
[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 14 '06 #9

P: n/a
VJ
Victor Bazarov wrote:
VJ wrote:
>>Forgot to
#include <string>
but my program compiled. It is probably included in the iostream (at
least in the library I am using)


But you shouldn't rely on that.
Yes, I dont. When reviewing my own code, I always include missing
headers (like in this case), alhtough it compiled well.

But this time, I didnt review this example ;)
Nov 15 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.