New course! Every coder should learn Generative AI!
Try a free lesson+ 4
Try to revisit your code there most be a mistake that is causing it not to run properly.
+ 3
But you know that the index starts at 0 and the last index is length() - 1? ;)
+ 2
Szymon
I found this about npos:
http://www.cplusplus.com/reference/string/string/npos/
I am wondering if you really know what npos is. I don't understand it and would be interested in how you get the idea to use npos.
+ 2
Okay, now I got it. In the reference about string.find() it is mentioned that it returns npos if no matches were found.
Thanks.
+ 1
I think your second loop is wrong.
i = 0 -> p.length() - 0 = p.length()
p[p.length()] out of bounds -> should be garbage value.
In java you would get an exception.
+ 1
Szymon
I have my doubts about this:
p[i] = (char) 0.
The char is not visible. But did you check p.length() after the first loop? Not visible is not the same as not there.
I would say there is still a char.
How does your java code looks like? Can't you convert your java code to c++?
+ 1
Your code is not working. It does not remove all non letters.
I don't think that npos is helpful here.
Btw:
Why don't you just print p in reversed order with the condition that p[i] is inside alpha?
pseudo code:
for i = length - 1; i >= 0; i-- :
if p[i] in alpha : print p[i]
else continue
+ 1
Nothing's wrong with this system... just change the last code to "cout << d.length()" to find the mistake
I'll give you a hint:
Your code has made a mess of whitespace
(I don't know c++.. it's just my idea)
0
Szymon
Can you please show me your new code?
0
Szymon
And erase? Maybe you did something there. But you deleted your code. So I can't test it.
- 2
any one can help me?
- 3
Samsung 8