cflores89
asked on
How do I split a cin << string into integers?
Hey All,
I'm looking for a way to input 10 ints from a string.
I've tried the code below it doesn't work, since it is expecting th NULL. And other examples on here use char with built in text so that you can use NULL in the while loop. I then tried with the EOL but I run into char to int comparisons.
Ideally, I'd liek something simple like Java
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
for (String s_in: args){
System.out.println(s_in);
}
Thank you
I'm looking for a way to input 10 ints from a string.
I've tried the code below it doesn't work, since it is expecting th NULL. And other examples on here use char with built in text so that you can use NULL in the while loop. I then tried with the EOL but I run into char to int comparisons.
Ideally, I'd liek something simple like Java
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
for (String s_in: args){
System.out.println(s_in);
}
Thank you
{
char inputString[200];
const char EOL = '\n';
char delims[] = " ";
char *result = NULL;
result = strtok(inputString, delims);
while (result != EOL)
{
// conver to int and add to Q here
}
/*
fillQ[x].enqueue(768);
fillQ[1].enqueue(685);
fillQ[2].enqueue(767);
fillQ[3].enqueue(663);
fillQ[4].enqueue(250);
fillQ[5].enqueue(755);
fillQ[6].enqueue(386);
fillQ[7].enqueue(893);
fillQ[8].enqueue(544);
fillQ[9].enqueue(740);
*/
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
stringstream was what i was looking for