The particular digit in the number of total

Jake

When you have such a definition:

int variable = 253243243;

Can I somehow refer for example to the third digit in this number? Something along the lines of vector or array? I need this to compare whether a certain digit in the number corresponds to a different figure given by the user. Is it even possible?

piokuc

You can extract digits with a combination of % and / operations.

Alternatively, you can print the number to a string using stringstream and extract digits as characters from the string:

std::stringstream ss;
ss << variable;
std::string s = ss.str();
unsigned char first = s[0] - '0'; // this is the first digit (from left)
unsigned char second = s[1] - '0'; // this is the second digit (from left)

Alternatively, if you are lucky enough to use a C++11 conforming compiler, you can use std::string::to_string function instead of std::stringstream.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Finding a number at a particular digit in a number

From Dev

Finding a number at a particular digit in a number

From Dev

how to match all 3 digit except a particular number

From Dev

IP DSCP = 8 makes IP total length to be a 7 digit number

From Dev

Count total number of files in particular directory with specific extension

From Dev

Count total number of files in particular directory with specific extension

From Dev

Regexp for a particular word with a digit

From Dev

Get all the user's name or total number of user in particular area in Google map

From Dev

How to get the total number of rows with particular value in json file in d3.js

From Dev

Return the nth digit of a number

From Dev

Regex for two digit number

From Dev

Add digit of number

From Dev

Buffer for a 3 digit number

From Dev

Getting the left digit of number?

From Dev

C - Position of digit in a number

From Dev

know the highest digit of a number

From Dev

Type for 64 digit number

From Dev

1000 digit number is Fibonacci number or not

From Dev

Total disk usage for a particular user

From Dev

Validation with total 4 digit and only 2 digit after decimal

From Dev

How to get count of particular column value from total number of records and display difference in two different columns in SQL Server

From Dev

Look for a particular number and sort it

From Dev

Masking number at a particular position

From Dev

Number of occurrences of a number in a particular range?

From Dev

Having some 'two digit number' <= 'single digit number' jQuery issues

From Dev

Having some 'two digit number' <= 'single digit number' jQuery issues

From Dev

bash not recognizing double digit number

From Dev

Returning the biggest three digit number

From Dev

Validating 7 digit phone number

Related Related

  1. 1

    Finding a number at a particular digit in a number

  2. 2

    Finding a number at a particular digit in a number

  3. 3

    how to match all 3 digit except a particular number

  4. 4

    IP DSCP = 8 makes IP total length to be a 7 digit number

  5. 5

    Count total number of files in particular directory with specific extension

  6. 6

    Count total number of files in particular directory with specific extension

  7. 7

    Regexp for a particular word with a digit

  8. 8

    Get all the user's name or total number of user in particular area in Google map

  9. 9

    How to get the total number of rows with particular value in json file in d3.js

  10. 10

    Return the nth digit of a number

  11. 11

    Regex for two digit number

  12. 12

    Add digit of number

  13. 13

    Buffer for a 3 digit number

  14. 14

    Getting the left digit of number?

  15. 15

    C - Position of digit in a number

  16. 16

    know the highest digit of a number

  17. 17

    Type for 64 digit number

  18. 18

    1000 digit number is Fibonacci number or not

  19. 19

    Total disk usage for a particular user

  20. 20

    Validation with total 4 digit and only 2 digit after decimal

  21. 21

    How to get count of particular column value from total number of records and display difference in two different columns in SQL Server

  22. 22

    Look for a particular number and sort it

  23. 23

    Masking number at a particular position

  24. 24

    Number of occurrences of a number in a particular range?

  25. 25

    Having some 'two digit number' <= 'single digit number' jQuery issues

  26. 26

    Having some 'two digit number' <= 'single digit number' jQuery issues

  27. 27

    bash not recognizing double digit number

  28. 28

    Returning the biggest three digit number

  29. 29

    Validating 7 digit phone number

HotTag

Archive