I just started learning C++ in Qt and I was wondering how can I put a variables result in a string? I’m trying to use this for a simple application where someone puts their name in a text field then presses a button and it displays there name in a sentence. I know in objective-c it would be like,
NSString *name = [NSString stringWithFormatting:@"Hello, %@", [nameField stringValue]];
[nameField setStringValue:name];
How would I go about doing something like this with C++? Thanks for the help
You don´t mention what type your string is. If you are using the standard library then it would be something along the lines of
That works for concatenating strings, if you want to insert other complex types you can use a stringstream like this:
Qt probably has its own string types, which should work in a similar fashion.