求助C++问题,请教

来源:百度知道 编辑:UC知道 时间:2024/07/16 08:34:11
求助:请问如下程序用C++该如何写?谢谢读取C:/1.txt中n的值和m的值,并显示在屏幕上,1.txt文件内容如下:n=25;m=35

#include<iostream>
#include<fstream>
#include<cctype>
using namespace std;
int main()
{
ifstream fin("c:\\1.txt");
int m(0),n(0);
char ch;
while(fin>>ch)
if(isdigit(ch))
{
for(n=ch-48;fin>>ch&&isdigit(ch);n=n*10+ch-48);
cout<<"n="<<n<<";m=";
while(fin>>ch)
if(isdigit(ch))
for(m=ch-48;fin>>ch&&isdigit(ch);m=m*10+ch-48);
cout<<"m="<<n<<endl;
}
fin.close();
return 0;
}

#include<iostream>
#include<fstream>
#include<cctype>
using namespace std;
int main()
{
ifstream fin("c:\\1.txt");
int m(0),n(0);
char ch;
while(fin>>ch)
if(isdigit(ch))
{
for(n=ch-48;fin>>ch&&isdigit(ch);n=n*10+ch-48);
cout<<"n=&qu