Strings

Nov 28, 2018 at 2:53pm
what is wrong with this code, why would cout not take the string ?

it breaks on line 17 and 22.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 // Name of program mainreturn.cpp 
#include <iostream> 
using namespace std;

int main(int argc, char** argv)
{
	cout << "You have entered " << argc
		<< " arguments:" << "\n";

	for (int i = 0; i < argc; ++i)
	{
		cout << argv[i] << "\n";
		
		// convert char ** to string , commmand line args are char **
		string a = argv[i]; 

		cout << a << "\n";
	}
		
	string ab = "afd";

	cout << ab << endl; 


	return 0;
}
Last edited on Nov 28, 2018 at 2:54pm
Nov 28, 2018 at 3:00pm
Perhaps you also need to
#include <string>
Nov 28, 2018 at 3:06pm
What do you mean it "breaks"? Are you getting compiler errors? Linker errors? Runtime errors?

Why are you withholding the details of your problem from us?
Nov 28, 2018 at 3:07pm
how come we can do this in C++ ,

string a = argv[i];

should we not use some built in function to convert Char ** to string ?
Nov 28, 2018 at 3:22pm
If you're going to ignore the questions we ask you, why would you expect us to answer the questions you ask us?
Nov 28, 2018 at 3:40pm
He already answered the question for you.
Nov 28, 2018 at 3:50pm
should we not use some built in function to convert Char ** to string ?

argv[i] is a char* , not a char**.

string a = argv[i]; does use a built in function; https://en.cppreference.com/w/cpp/string/basic_string/operator%3D
Nov 28, 2018 at 4:05pm
masterinex wrote:
He already answered the question for you.

Who answered what question?

I asked:

MikeyBoy wrote:
What do you mean it "breaks"? Are you getting compiler errors? Linker errors? Runtime errors?

I haven't seen your anwer to that question. If you're not going to bother answering the questions other people ask you, when trying to figure out how to help you, then how can you expect us to answer your questions?
Last edited on Nov 28, 2018 at 4:12pm
Nov 29, 2018 at 6:54am
Do you see how other people are able to answer my question without having me to provide all the details. i am giving some very basic code and you can try it on your own to figure out what errors you get . I also love how you jump directly into conclusion that I am going to withold information from you.

Why are you withholding the details of your problem from us?
Nov 29, 2018 at 7:57am
Last edited on Nov 29, 2018 at 7:57am
Nov 29, 2018 at 10:27am
If people had enough knowledge to ask smart questions they probably wouldn't need to ask questions, they could solve their problems on their own.
Nov 29, 2018 at 11:58am
Do you see how other people are able to answer my question without having me to provide all the details. i am giving some very basic code and you can try it on your own to figure out what errors you get .

You've asking people to give up their time and effort, free of charge, to help you. The onus is on you to do as much of the leg-work as possible, to minimize the amount that the people generously offering to help you have to do.

I also love how you jump directly into conclusion that I am going to withold information from you.

I said nothing about what you were going to do, only what you have actually done. You had information that would have made it easier for us to help you. Given the choice between sharing that information with us, and keeping it to yourself, you chose the latter.

You would do well to read the link mbozzi posted.

EDIT: Oh, and thanks for the abusive PM. It's always nice to start my day with a chuckle :)
Last edited on Nov 29, 2018 at 11:59am
Topic archived. No new replies allowed.