You can use something like this:
std::string integers;
//Gathering Integers:
cout << "Please enter a series of integers with nothing between them.";
cin >> integers;
int sum = 0;
for (char c : integers)
if (c >= '0' && c <= '9')
sum += c - '0';
To explain what above code does, I believe first couple of lines are apparent, I will skip to for() loop. This is form of foreach loop used in C++. It grabs character by character from string and stores it in variable (in this case in c), and inside a loop we have normal checking if c is ASCII representation of number 0 to 9. Following that ASCII representation is converted to integer (c - '0').
Your approach is comparing integers with ASCII characters, you can try this:
if(integers[i] >= '0' && integers[i] =< '9' && integers != '\0') {
sum = integers[i] - `0`;
}
You also have a problem:
integers != "\0"
should be:
integers[i] != '\0'
"" is representation of string and even if you have "" it is an empty string but in contains \0 in it. In the case above "\0" contains '\0\0'. So basically what you want is to comparing single character with \0 where as you are comparing string with \0\0.
Yet another error:
int size;
...
char integers[size];
...
cin >> integers; // SEGFAULT HERE
size = strlen(integers);
uninitialized variables are undefined behavior in C++ and might contain garbage, from 0 to MAX_INT. You might get segfault if size is 0 and you later try to enter more than 0 characters into integers. You will segfault before you even reach size = strlen().
Another uninitialized variable:
int size;
I actually got 432552 as my output from your program after fixing all those errors mentioned above.
Here is your debugged code:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
//Declaring Variables & Character Array:
int size = 100; // UNINITIALIZED VARIABLE
int sum = 0; // UNINITIALIZED VARIABLE
char integers[size];
//Gathering Integers:
cout << "Please enter a series of integers with nothing between them.";
cin >> integers;
//Gathering Size of String:
size = strlen(integers); // +1 ??? why
//Adding up Contents Within String:
for(int i = 0; i < size; i++)
{
// integers[i] >= 0 is comparing char to int
// integers[i] <= 9 is comparing char to int
// ingegers == "\0" is comparing entire string with stirng which contains "\0":s
// < and > shoudl be <= nad >= to include 0 and 9
if(integers[i] >= '0' && integers[i] <= '9' && integers[i] != '\0')
{
// sum = integers[i]++; is incrementing character at integer[i]` not `sum`
sum += integers[i] - '0';
}
}
//Outputting Sum:
cout << sum;
return 0;
}
Hah just realized another error you had: strlen() returns length of integer lets say string s="ABCD" is given strlen(s) will return 4, and later in for() loop loop goes from 0 and up to 4 but not including 4 since s[0] = 'A', s[1] = 'B', s[2] = 'c' and s[3] = 'D'.
Ok, so to further explain, characters have digital values as well:

If you see all characters have decimal values: here is short table of charcters 0 - 9 from ascii table above:
Character | Decimal Value
----------+--------------
0 | 48
1 | 49
2 | 50
3 | 51
4 | 52
5 | 53
6 | 54
7 | 55
8 | 56
9 | 57
so by doing this:
integers[i] - '0'
is basically like saying
integers[i] - 48
if integer[i] is 8 it will hold decimal value of 56. So 56 - 48 would give integer value of 8