471,086 Members | 1,109 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

main(int arc, char *argv[])

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
9 6251
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
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
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
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
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
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
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
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
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.

Similar topics

19 posts views Thread by Steven T. Hatton | last post: by
13 posts views Thread by Sokar | last post: by
3 posts views Thread by Bill Cunningham | last post: by
2 posts views Thread by significantBit | last post: by

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.