Click here to Skip to main content
15,917,568 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to take input as a input array in c++

Eg

int ar[10];

If user type : 123241

it should be like this--->>
ar[0]=1
ar[1]=2
ar[2]=3
ar[3]=2 and so on....
Posted
Comments
André Kraak 27-Aug-11 17:53pm    
Do you have any code we can comment on?
With the answer from your previous questions you should be able to put something together.

1 solution

C++
string str;
cin >> str;
const char* cstr = str.c_str();

int* intArray = new int[str.length()];

int i;
for(i = 0; i < str.length(); i++)
    intArray[i] = cstr[i] - '0';
 
Share this answer
 
Comments
Philippe Mori 27-Aug-11 18:23pm    
And don't forghet delete[] intArray at the end.
Simon Bang Terkildsen 27-Aug-11 18:29pm    
thank you for adding that. To the OP you'll do delete[] intArray once you're done with intArray

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900