A practical help
Would there be a way to do this simplier?
Instead of this
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")
(pre2 == int'\n')
I know its not good but you can get the idea what i mean.
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.
Edit: Sorry i just noticed you said || and not &&.
besides, Elysia got a way easier solution.
bool bMatch = false;
for (int i = 0; i <= 9; i++)
if ( pre2 != ('0' + i) )
bMatch = true;
if (pre == '\n' && bMatch); // Your code
if (isdigit(pre2) && pre2 == '\n')
Why not just
if (pre2.length() == 2 && isdigit(pre2) && pre2 == '\n')
Because out-of-bounds memory accesses are A-ok?
Originally Posted by Elysia
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.
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.
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 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.