Hi, I am a beginner and new here. I have a question which might be very easy for you all so thought of asking a good solution.
I need to read an integer from console into an array in c++ , can any one please help!
for example: I want output should be like
Enter number
user enters: 1234
the contents should get stored in an array as a[0]=1 ,a[1]=2,a[2]=3,a[3]=4

Any idea on this would be a great help, either in the form of one liner code or construct that I think I am missing because I am new to ths language.

Many thanks

Recommended Answers

All 4 Replies

Member Avatar for iamthwee

Start with the basics:

#include <iostream>
#include <string>

using namespace std;

int main()
{
  //code goes here

 return 0;
}

Hi I started up with this code block though,but stuck at some construct or language rule that I am missing

   int arr[20];
   char *input;
   input =new char[20];

 cout<<"enter  input number";
    cin>>input;//some constuct here to read number from console ??
for(int i=0;i<10;i++){
arr[i]=input[i];}

I want that if I enter number as 12345
then my variable 'input' should store this number as innput[0]=1..input[4]=5
Is there any way out for this and another thing i should know that user has hit 'Return key' so a construct to check that user input is finished.

Help is much appreciated
Thanks

So what's not working right? How can you tell?

when asking for help, you must tell us what's going on, not just say "it doesn't work". There are hundreds of ways it can fail. Which one is yours?

It is solved now
Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.