+ 3
Help with this to solve my problem.
I need to write a program that takes a string that contains two numbers seperated by a comma that represent the width and height. I could change them to an integer using the stoi() function, but how can I tell the program that the first part of the number is the width and the second is the height. I'been searching on google and Youtube a lot lately and I didn't find any answer.
10 Answers
+ 5
Mohammed Seems quite long when you could just do the following for an input string `s`:
auto width = std::stoi(s);
auto height = std::stoi(s.substr(s.find(',') + 1, s.length()));
+ 3
Why do you want to tell the program that the first part is width and the second is height? Just use a variable to identify it for yourself(like "height" to refer to the height and "width" to refer to the width)
+ 3
Use the code below, just don't use a space after comma, the input of the code below should be "13,19" but without any space, I'll let you convert them after splitting them into two strings.
https://code.sololearn.com/c61yXCIrMhZX/?ref=app
+ 3
Shadow
Thanks, that was helpful.
+ 3
Anoir B'f ohh, i guess I misunderstood the questionđ
or the question itself isn't clear. It should've been more like "how to extract then height and width" or something like that
+ 2
Thank you so much Mohammed
+ 2
Rishi its because the program should take a string that contains two numbers seperated by a comma, and figure out wich one is the height and wich is the width.
+ 2
Ajay Prakash refer here
https://www.google.com/
- 1
Mucho texto
- 2
Different between c and python code