36、读取一行包含空格的数据

#include<iostream>
#include<fstream>
using namespace std;
void str(){  //读取一行数据放入字符串中
  string str;
  getline(cin,str);
  cout<<str;
  system("pause");     
} 

void str2(){  //读取一行数据 放入字符数组中
  char a[80];
  cin.getline(a,80);
  cout<<a;
  system("pause");     
} 

void str3(){  //一次性读取一个字符 
 char c;
 while((c=getchar())!='\n'){
    cout<<c;                           
 }
  system("pause");     
} 


void str4(){  //
   
   int  a,b,c,space;
   
   ifstream fin("in.txt");
   
   ofstream fout("out.txt");
   
   a=fin.get()-'0'; //读取数字 
   
   space=fin.get();//读取空格 
   
   b=fin.get()-'0'; 
   
   space=fin.get();
   
   c=fin.get()-'0'; 
   
   cout<<a*b*c;
   
   fin.close();
   
   fout.close();
 
} 


int main(){  //1、用gets 读取数据   
  char a[100];
  gets(a);
  puts(a);
  system("pause");
} 

猜你喜欢

转载自blog.csdn.net/qq_30272539/article/details/81335745