View Full Version : Joining Variables in C++
startherepodcast
October 30th, 2007, 11:35 AM
Hey,
I'm am just starting out in c++ and I have come across a problem to which I have not been able to find an answer. I need to join to variables together so that I can have part of a string in quotes and then add to it a variable.
Thanks..
aks44
October 30th, 2007, 02:16 PM
Care to elaborate?
What exactly are you trying to do? Please give examples, as I find your question pretty confusing/confused.
startherepodcast
October 30th, 2007, 02:27 PM
What I am trying to do is pass a command to curl via system() to post to a php script.
string curl = "curl -F var1=";
string var1 = "Hello World";
system(Joint_Variable_Goes_Here)
How Could I Join these two strings together so that I could execute the command.
Thanks
aks44
October 30th, 2007, 02:36 PM
If I understood correctly the "so that I can have part of a string in quotes" part, here it is:
std::string curl = "curl -F var1=";
std::string var1 = "Hello world";
std::string result = curl + "\"" + var1 + "\"";
system(result.c_str());
The above code assumes that you don't have any double-quotes in var1. If you may have some, you'll have to escape them beforehand.
startherepodcast
October 30th, 2007, 03:42 PM
Thanks that seems to work great. Could you also Please tell me where I can find some more tutorials on c++ ,and some example code, if you know any.
Thanks...
aks44
October 30th, 2007, 03:50 PM
Twhere I can find some more tutorials on c++ ,and some example code, if you know any.
You could try Bruce Eckel's free Thinking in C++ (http://mindview.net/Books/TICPP/ThinkingInCPP2e.html) book. It's not for complete newbie programmers, but it teaches correct C++ AFAIK.
I never read it though, those kind of books tend to bore me to death. :oops:
LaRoza
October 30th, 2007, 03:53 PM
My wiki has many references on C++. You might find what you want in the string header.
startherepodcast
October 30th, 2007, 04:39 PM
Thanks for those suggestions. I'll check them out and hopefully improve my skills a bit in the way of C++.
Thanks Again For All Your Help
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.