1

I have a small python script that opens a url built up from a string input byt the users and a pre-defined variable, which looks like this;

sn = str(input("Input here"))
url = 'http://URLPART1' + sn + '.URLPART2'

if sys.platform == 'win32':
    webbrowser.open_new_tab(url)

elif sys.platform == 'darwin': # OSX
    subprocess.Popen(['open', url])

Now, I'm trying to write the Windows part in C++ and I've tried a few different approaches but I'm not quite sure how to concatenate the strings in C++ as I did in python using '+'.

This is one of my attemps;

 int main ()
 {
    int sn;
    string sn2, url;
    cout << "UserInputHere: ";
    cin >> sn;
    sn2 += std::to_string(sn);
    std::string A = ("http://myurl1");
    std::string B = (".myurl2");

    url = A + sn2 +B; // or url << A + sn2 << B?

    ShellExecute(NULL, "open", 'url', NULL, NULL, SW_SHOWNORMAL);

    return 0;
 }

Can someone show me how to re-write the line; std::string url = A + sn + B; into something C++ will understand or maybe the whole approach is wrong?

Many thanks,

Editted.

Skyone
  • 13
  • 4
  • https://stackoverflow.com/questions/191757/c-concatenate-string-and-int – Baum mit Augen Dec 15 '16 at 15:46
  • Clearly this was jumped on quickly; do notice that in python you have `str(input("Input here"))` which is converting the `int` to a string and you need to do likewise in C++ – doctorlove Dec 15 '16 at 15:48
  • Oversight on my side, I had already added that but I forgot to add the post.I tried sn2 += std::to_string(sn); to no avail. – Skyone Dec 16 '16 at 14:58

0 Answers0