1
My professor of algorithms and programming techniques passed an exercise in which a = "123567348"
and from that I would say which numbers are even and which are prime. He said he would have to use substr()
, and passed an example:
#include <stdio.h>
#include <string>
int main ()
{
int c;
char a [] = "123456789", pedaco;
for (c = 1; c <= 10 ; c++)
pedaco = a.substr(c,1);
return 0;
}
but returns the error:
8 12 [Error] request for Member 'substr' in 'a', which is of non-class type 'char [10]'
In the example he gave was: pedaco = substr(a,c,1);
and it didn’t work either.
If each piece is only a letter, why not access directly with
a[c]
? (and would have to start at Indice 0)– Isac