+ 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.

17th Feb 2022, 3:46 PM
Anoir B'f
Anoir B'f - avatar
10 Respostas
+ 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()));
17th Feb 2022, 4:48 PM
Shadow
Shadow - avatar
+ 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)
17th Feb 2022, 4:27 PM
Rishi
Rishi - avatar
+ 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
17th Feb 2022, 4:33 PM
Mohammed
+ 3
Shadow Thanks, that was helpful.
17th Feb 2022, 5:28 PM
Mohammed
+ 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
18th Feb 2022, 2:19 AM
Rishi
Rishi - avatar
+ 2
Thank you so much Mohammed
17th Feb 2022, 4:47 PM
Anoir B'f
Anoir B'f - avatar
+ 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.
17th Feb 2022, 4:55 PM
Anoir B'f
Anoir B'f - avatar
18th Feb 2022, 2:18 AM
Rishi
Rishi - avatar
- 1
Mucho texto
19th Feb 2022, 4:00 AM
Emmanuel Gutiérrez
Emmanuel Gutiérrez - avatar
- 2
Different between c and python code
17th Feb 2022, 9:01 PM
Ajay Prakash
Ajay Prakash - avatar