Thread: How to read uint8_t data type from command line input

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    Question How to read uint8_t data type from command line input

    Hi All,

    Here is my simple program
    Code:
    #include<iostream>
    using namespace std;
     
    int main()
    {
    uint8_t sa[6];
    cout<<"enter addr"<<endl;
     
    for(int i=0;i<6;i++)
    cin>>sa[i];
     
    for(int i=0;i<6;i++)
    cout<<"Address sa["<<i<<"]"<<sa[i]<<endl;
     
    system("pause");
    return 0;
    }
    when i input values from console
    12
    21
    21
    22

    my array should read
    sa[0] 12
    sa[1] 21

    but instead
    it reads
    sa[0] 1
    sa[1] 2

    how can I have these values entered or modify my program to make my sa[0] to have 12 and not a single element

    please help me with this
    I want to use uint8_t data type only

    Thanks to all for reading this post.
    Looking forward to your help.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    That's because on many systems uint8_t will be a "char". So basically, you're reading a char. I'm not sure if you can modify input streams to read an integer instead, but the easiest is to read it into an integer variable first.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    2
    Thanks EVOEx.

    I will change inpit stream to integer and then convert to hex . I will then assign it to uint8_t data type.
    Hope it works.

    Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. input data type
    By QuestionKing in forum C++ Programming
    Replies: 3
    Last Post: 12-09-2009, 06:50 AM
  2. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  3. Line of data input method
    By larry_2k4 in forum C Programming
    Replies: 2
    Last Post: 04-28-2009, 11:34 PM
  4. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-08-2007, 12:24 AM
  5. Message printing problem
    By robert_sun in forum C Programming
    Replies: 1
    Last Post: 05-18-2004, 05:05 AM