c++ 刷题之输入输出 发表于 2019-02-28 | 分类于 刷题 刷多了LeetCode,就容易把基本的输入输出给忘了,但是有些OJ得自己输入输出,总结一波,以备不时之需 。 ++1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495#include <iostream>#include <stdio.h>#include <string>#include <cstring>#include <vector>using namespace std;void split(string s,string separator,vector<string>& vec);int main(int argc, char **argv) { //c++ 多行整型// int a,b,c;// while(cin>>a>>b>>c){//ctrl+d// cout<<a<<b<<c<<endl;// }// cout<<"DONE!"<<endl; //c 多行整型// int a,b,c;// while(scanf("%d%d%d",&a,&b,&c)!=EOF){//linux ctrl+d结束输入;windows ctrl+z结束// if(!(a||b||c)) break;// printf("%d,%d,%d\n",a,b,c);// }// printf("%s","DONE!"); //c++ 多行短字符串,无空格隔开 & 字符串修改// string a;// while(cin>>a){// cout<<"cout:"<<a<<"len:"<<a.length()<<endl;// }// string finish="DONE!";// finish[2]='O';// finish[3]='O';// cout<<finish<<endl; //c 多行短字符串,无空格隔开 & 字符串长度// char buf[255];// while(~scanf("%s",buf)){// int len=strlen(buf);// printf("printf: %s,end:%d",buf,len);// }// char finish[]={'D','O','N','E'};// printf("%s",finish); //c++ 一行一行字符串读入,长字符串有空格// string str;// char str[255];// while(getline(cin,str)){// cout<<"str: "<<str<<" len:"<<str.length()<<endl;// }// while(cin.getline(str,255)){// cout<<"str: "<<str<<" len:"<<strlen(str)<<endl;// }// cout<<"DONE!"<<endl; //c 一行一行字符串读入,长字符串有空格// char buf[255];// while(gets(buf)){// printf("buf:%s\nlen:%d\n",buf,strlen(buf));// }// printf("%s","done!"); //输入,输出二维矩阵// char arr[100][100];// string line[100];// for(int i=0;i<3;i++){//c++ cin,cout;c scanf,gets,printf// cin.getline(arr[i],255);// getline(cin,line[i]);// gets(arr[i]);// }// cout<<endl;// for(int i=0;i<3;i++){// cout<<line[i]<<endl;// printf("%s\n",arr[i]);// } //string与int互转// string s="123";// cin>>s;// int a=atoi(s.c_str());// float a=atof(s.c_str());// int a=37847;// string b=to_string(a);//to_string()对于参数为浮点数,返回的结果跟cout不一样// cout<<b<<endl; //字符串分割// string s="you are great!";// vector<string> res;// split(s," ",res);// for(string item:res)// cout<<item<<endl;}// void split(string s,string separator,vector<string>& vec){// int subStrPosStart=0;// int separatorIdx=s.find(separator,subStrPosStart);// while(separatorIdx!=string::npos){// vec.push_back(s.substr(subStrPosStart,separatorIdx-subStrPosStart));// subStrPosStart=separatorIdx+separator.length();// separatorIdx=s.find(separator,subStrPosStart);// }// if(subStrPosStart!=s.length())// vec.push_back(s.substr(subStrPosStart));// // }