写于2012
方法一:
#include "stdafx.h" #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { FILE *fp; if ((fp=fopen("D:\C++\project\string.in","r"))==NULL) { printf("cannot open the file."); } double a1=0,a2=0; fscanf(fp,"%lf",&a1); fscanf(fp,"%lf",&a2); fclose(fp); printf("a1:%f.a2:%f ",a1,a2); printf("Result:%.2lf ",a1+a2); }
方法二:
#include "stdafx.h" #include <string> #include <cmath> #include <iostream> using namespace std; double string_process(string &ch) { bool pos_flag=false,dot_flag=false,pow_flag=false; double int_part=0,flo_part=0,pow_part=0; int j=0; int k=1; for(;ch[j]!='