basic_istream_char* __cdecl basic_istream_char_read_complex_double(basic_istream_char *this, complex_double *v) { double r; basic_ios_char *base = basic_istream_char_get_basic_ios(this); TRACE("(%p %p)\n", this, v);//wine里用来追踪变量的,功能跟printf差不多 /* 因为正确的格式里只有real 和 (real)还有(real,imaginary),所以只会在流里取相应字符 */ ws_basic_istream_char(this);//先用ws()将流里开头的空白都去掉 //用peek()看看流里第一个字符是什么,不取出来 if(basic_istream_char_peek(this) == '(') { char c; basic_istream_char_get(this);//用get()取流第一个字符'(',不保存(因为不需要) basic_istream_char_read_double(this, &r);//读流里的double if(ios_base_fail(&base->base))//如果不是double类型,返错退出 return this; ws_basic_istream_char(this);//接着又用ws()去掉接下来的空格(' ','\t') c = basic_istream_char_peek(this);//用peek()把字符存到c,但不从流里取出 if(c == ',') { double i; basic_istream_char_get(this);//字符是',',complex正常格式,取出 basic_istream_char_read_double(this, &i);//继续读double if(ios_base_fail(&base->base))//返回 return this; ws_basic_istream_char(this);//继续去空格 c = basic_istream_char_peek(this);//用法同上 if(c == ')') { /* 格式(real, imag) 所以get从流里取走'('*/ basic_istream_char_get(this); v->real = r; v->imag = i; }else { basic_ios_char_setstate(base, IOSTATE_failbit); return this; } }else if(c == ')') { /* 格式 (real) */ basic_istream_char_get(this); v->real = r; v->imag = 0; }else { basic_ios_char_setstate(base, IOSTATE_failbit); return this; } }else { /* 格式 real */ basic_istream_char_read_double(this, &r); if(ios_base_fail(&base->base)) return this; //如果是(12)这样的格式,只是取实数,虚数为0 v->real = r; v->imag = 0; } return this; }
原文地址:http://blog.csdn.net/christopherwu/article/details/44199953