イテレータを文字列に追加すると、予期しない文字列の動作が発生しています。C++に文字列ポインタを追加する
int x := 10;
print x;
私は、このファイルの内容を含む、既に文字列を持っている、と私はそれを反復処理し、単に今の空白を削除しています:基本的に、私はの線に沿って何かを読み込むファイルを持っています。
void Lexer::parse()
{
Pointer = Filestring.begin(); // both private members
while(Pointer < Filestring.end())
{
if(is_whitespace(0)) // 0 indicates current Pointer position
{
advance(Pointer, 1);
continue;
}
CurToken.append(&*Pointer); // CurToken is private member string
advance(Pointer, 1);
}
cout << CurToken << endl;
}
私はCurTokenがすべての空白が削除された文字以外の文字列であると期待しています。私は問題はポインタを参照解除されたと仮定し、もしそうなら、どのように私は、現在を追加することができ
rint x;
int x;
nt x;
t x;
x;
;
...
int x := 1 + 2;
print x;
nt x := 1 + 2;
print x;
t x := 1 + 2;
print x;
:代わりに、私は次のような何かを得ますポインタの位置の文字?私はそれがないデrefrenceをすれば、私は
invalid conversion from ‘char’ to ‘const char*’
で終わる注: is_whitespace()私がテストし、期待どおりに動作しています。それは起こりうる問題として排除することができます。
「ポインタ」とは何ですか? – karlphillip
なぜあなたは 'Pointer'の代わりに' it'を書いておらず、 'advance(Pointer、1)'の代わりに '++ it'をしていますか?また、 'is_whitespace(0)'の代わりに['std :: isspace(* it)'](http://en.cppreference.com/w/cpp/string/byte/isspace)を使うのはなぜですか?あなたは不必要に複雑にしています。 – Nawaz
ポインタは文字列イテレータ* – grep