The comments in the code indicates what I am trying to do, however this is all I am able to come up with. But from here I am stuck. Is there a way to make this simpler and modify it to do what I would like it to do?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Write a main function that takes two values
// as arguments and prints their sum
#include <iostream>
#include <string>
usingnamespace std;
int main(int argc, char **argv)
{
string str;
for(int i = 1; i != argc; ++i)
str += string(argv[i]) + " ";
cout << str << endl;
return 0;
}
// Write a main function that takes two values
// as arguments and prints their sum
One would think that your two values would be numbers. Yet you are dealing with them as "strings".
Is there a way to make this simpler and modify it to do what I would like it to do?
I see no way to make this any simpler right now. It contains all the cede necessary to get the job done. Beyond that I have no idea what you want it to do.
An example of what is on the command line and what you are wanting for output would help.
This is all that I am able to come up with but now there is the issue of not having it in a main function.
Not having what (it) in the "main" function?
I asked you for an example of what is on the command line. And what your expected output should be.
I am still waiting.
Your last bit of code is adding two numbers.
Should I take this as being what you need?
I came up with this. It will work with "strings" or numbers.