C语言文件读写

来源:互联网 发布:安卓模拟器知乎 编辑:程序博客网 时间:2024/06/08 06:15
#include <cstdio>#include<iostream>#include<string>#include<algorithm>#include<cstdlib>#include<stack>#include<queue>#include<cmath>#include<vector>#include<cstring>using namespace std; typedef struct{char name[20];}Id; /*class Exchange {public:    int exchangeOddEven(int x) {        int res=0;        int t;        stack<int> stk;        while(x)            {            t=x%2;            x/=2;            stk.push(t);        }        int n=stk.size();        if(n%2==1){            stk.push(0);            n++;        }        t=n;        int x1;int y;        //cout<<n;        int k=n/2;        for(int i=0;i<k;i++)            {             x1=stk.top();            stk.pop();             y=stk.top();            stk.pop();            //cout<<x<<" "<<y<<" ";             res+=y*pow(2,--n);            res+=x1*pow(2,--n);        }        return res;    }};*/class Parenthesis {public:    bool chkParenthesis(string A, int n) {        char ch;        int left=0;        for(int i=0;i<A.length();i++)            {            ch=A[i];            if(ch=='(')                left++;            else if(ch==')')                left--;            if(left<0)                return false;        }        if(left==0)return true;        else           return false;    }};int main()  {  //strcpy(st.name,"wang");/*vector<int> res;for(int i=0;i<6;i++)res.push_back(i);for(int i=0;i<6;i++){cout<<res[i]<<endl;res.pop_back(); } */  /*Parenthesis A;  string str="abc";if(A.chkParenthesis(str,str.length()))cout<<"yes";elsecout<<"no";*/char st[20];FILE *fp;char ch;/*fp=fopen("C:\\Users\\heisenberg\\Desktop\\test.txt","w");if(fp==0)//文件打开失败 {cout<<"NULL";exit(1);}cout<<"input a char:";ch=getchar();while(ch!='#'){fputc(ch,fp);ch=getchar();}fclose(fp);FILE *fp;*/fp=fopen("C:\\Users\\heisenberg\\Desktop\\test.txt","r");if(fp==0){cout<<"read fail";exit(1);}while((ch=fgetc(fp))!=EOF){putchar(ch);}putchar('\n');fclose(fp);return 0;//cout<<st; }   

原创粉丝点击