zoukankan      html  css  js  c++  java
  • C++实现读取文件,输出单词

    #include <iostream> 
    #include <fstream> 
    #include <string> 
    using namespace std; 
    
    int main() 
    { 
    	const char filename[]="f:\\text.txt"; 
        ofstream o_file;
        ifstream i_file;
        string out_text; 
    
    	//写 
        o_file.open(filename); 
        for(int i =0;i<=12;i++) 
    	{ 
    		o_file<< "a" << i <<' ';//将内容写入文本 
    	} 
        o_file.close(); 
    
    	//读 
        i_file.open(filename); 
        if(i_file.is_open()) 
    	{ 
    		while(i_file>>out_text)  
    			cout << out_text << endl; 
    	} 
    	else 
    		cout<<"打开文件:"<<filename<<"时出错!"; 
    
    	i_file.close();
    	return 0; 
    } 
    

      

  • 相关阅读:
    bash特性
    FHS 层级文件系统
    环境变量的问题
    linux认识
    搜索引擎的使用
    nginx
    部署操作手册
    git
    添加tag
    pycharm中使用git
  • 原文地址:https://www.cnblogs.com/phoenixzq/p/2210907.html
Copyright © 2011-2022 走看看