+ 3
How can i convert string into int array in c++?
20 Respostas
+ 3
What do you want to store in the int array ?
+ 2
Thank u for answering my questionđ
+ 1
I want to get a string of numbers from the user and store it in the array and then implement the QuickSort function on it
0
What is the language you want to use.
please add the language you use in the tags.
0
C++
0
How are the numbers separated ?
0
With spaces
0
Do u have any idea ?
0
There is no easy, ready made function in c++ to do this.
Use a while loop (till end of string)
Read string by character.
if it is a character, add it to a temp string
if it is another character, add it to the temp string
if it is a space, add the temp string to a string array
Loop throug string array and convert string to int.
Sorry do not know c++ that well.
0
Give example input and expected output.
Is you string a C++ string or a c-style character array?
0
I want to get a string of numbers from the user and store it in the array and then implement the QuickSort function on it
0
I want to run the QuickSort but my problem is that the user wants to give me a string of numbers as input
0
Still need more info:
"12345" => {1, 2, 3, 4, 5}
or
"12 23 34" => {12, 23, 34}
or
"12 23 34" => {1 ,2, 2, 3, 3, 4}
0
The second one
0
See
"12 1 45 6 -7" to {-7,1,6,12,45}
0
I just need a function to convert that
0
use strtok() to split the string and pushback into an int vector and using stoi to convert to int as you pushback.
or if you need an regular array, you would need to know how may numbers that are in the) string, you could count the number of spaces + 1 (assuming single space between the ints so you can declare an array of the correct size.
0
Ok thanks