[Solved]combining variables into system

Thanks to Grey Wolf for helping resolve the issue.

Hello guys I was wondering could someone assist me in the problem I am currently having?
I am making an auto-login script for me and my friends on a website and I am attempting it to prompt system() with something like the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main() {
	string k, L, p;
	cout << "~~Insert Username~~" << endl;
	cin >> k;
	cout << "~~Insert Password~~" << endl;
	cin >> p;
	cout << "Username: " << k << " Password: " << p << endl;
	cout << "Please type in your browser Firefox, or IE" << endl;
	cin >> L;
	string browser2;
	if(L == "Firefox"){
		browser2 = "start firefox.exe " <<"http://login.thesite/login.php&user=" << k << "&pass=" << p << "&nURI=http://adm.thesite/patrol/?id=start";
		system(browser2);
	}else if(L == "IE"){
		system("start iexplore.exe http://thesite");
	}else{
		system("start iexplore.exe http://thesite");
	}
	cout << "Website should have loaded." << endl;
}


But I get the following compile errors:
1
2
3
// main.cpp(17) : error C2296: '<<' : illegal, left operand has type 'const char [19]'
//main.cpp(17) : error C2297: '<<' : illegal, right operand has type 'const char [50]'
//main.cpp(18) : error C2664: 'system' : cannot convert parameter 1 from 'std::string' to 'const char *' 


In the code above I am only testing the script on Firefox for now. iexplore is left out.

Thank you for your time.
Last edited on
closed account (z05DSL3A)
try system( browser2.c_str() ); on line 17.
I fixed one error, but got many many more.
on line 16:
browser2 = "start firefox.exe " <<"http://login.thesite/login.php&user=" << k << "&pass=" << p << "&nURI=http://adm.thesite/patrol/?id=start";
got fixed to
browser2 = "start firefox.exe http://login.thesite/login.php&user=" << k << "&pass=" << p << "&nURI=http://adm.thesite/patrol/?id=start";


but upon fixing that and attempting what you suggested, I get errors that go into some file named ostream

heres the error which I assume ifs the most important nuisance

//main.cpp(16) : error C2677: binary '<<' : no global operator found which takes type 'std::string' (or there is no acceptable conversion)

[[Fixed, changed << to +]]
but how do I use & in the console?
1
2
3
4
5
6
'user' is not recognized as an internal or external command,
operable program or batch file.
'passd' is not recognized as an internal or external command,
operable program or batch file.
'nURI' is not recognized as an internal or external command,
operable program or batch file.

Last edited on
closed account (z05DSL3A)
Sorry, I was put off by main.cpp(17) : error C2... and looked at line 17 of the posted code.

You should use a stringstream[1] to build your string to pass into system();

[1] http://www.cplusplus.com/reference/iostream/stringstream/stringstream.html
I got the text to go into system, using the method you suggest. the only problem I am currently having is to find a way for & to not register as a new command inside the console.
closed account (z05DSL3A)
Add \" to the begining an end of the address.

ss << "start firefox.exe " <<"\"http://login.thesite/login.php&user=" << k << "&pass=" << p << "&nURI=http://adm.thesite/patrol/?id=start\"";
Awesome it worked that you so much!
Topic archived. No new replies allowed.