1. ## A practical help

Would there be a way to do this simplier?

Code:
```     if (pre2 == "0\n"||pre2 == "1\n"||pre2 == "2\n"||
pre2 == "3\n"||pre2 == "4\n"||pre2 == "5\n"||
pre2 == "6\n"||pre2 == "7\n"||pre2 == "8\n"||pre2 == "9\n")```
Something like
(pre2 == int'\n')
I know its not good but you can get the idea what i mean.

2. Wouldn't it be possible to have a function which took an int and a string and returned the int and the string as one string and then inset the function to replace the "0/n" part.

Something like:
Edit: Sorry i just noticed you said || and not &&.
besides, Elysia got a way easier solution.

3. One way:
Code:
```bool bMatch = false;
for (int i = 0; i <= 9; i++)
{
if ( pre2[0] != ('0' + i) )
{
bMatch = true;
break;
}
}
if (pre[1] == '\n' && bMatch); // Your code```
Or:
Code:
`if (isdigit(pre2[0]) && pre2[0] == '\n')`

4. Nice! Thank you Elysia!

5. Why not just
Code:
`if (pre2.length() == 2 && isdigit(pre2[0]) && pre2[1] == '\n')`

6. Incorrect code?

7. Originally Posted by Elysia
And
Code:
`if (pre2.length() == 2 && isdigit(pre2[0]) && pre2[1] == '\n')`
Could also be shortened to:
Code:
`if (isdigit(pre2[0]) && pre2[1] == '\n')`
Because out-of-bounds memory accesses are A-ok?

8. Not definitely not, but no-one says it IS out of bounds. I'll just have to assume you're doing some basic checks before.

9. Depending on the context of the OP's code, it's very possible that one or two of the conditions in my test might be known true and could be skipped, but at the moment, only the OP knows that.

10. Yes Robatino on second thought you're right , it depends on the context, that just i forgot to specify.

Actually i cant use either one because im gonna read a whole file once and pre2[0] would be the first character in the file however what i want is to find the combination of a number with \n in the file.

Thanks though for the help , it helped me to understand more the problem.