Strings

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
Perhaps you also need to
#include <string>
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?
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 ?
If you're going to ignore the questions we ask you, why would you expect us to answer the questions you ask us?
He already answered the question for you.
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
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
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?
Last edited on
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.
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
Topic archived. No new replies allowed.