c++读一行一行读取

jackxiang 2008-1-21 16:46 | |
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream fin("MyData.txt");
string str; while(getline(fin,str))
{
//一行一行地读,直到失败为止  
cout<<str<<endl; //显示出来  
}
return 0;
}



#include   <iostream>
#include   <string>
#include   <fstream>
using   namespace   std;

int   main()
{
    ofstream   outfile;
    ifstream   infile;
    char   value;
    outfile.open("a.txt");

    outfile   <<   "abcd";
    outfile.close();
    infile.open("a.txt");
    if   (infile.is_open())
    {
        while(infile.get(value))
            cout<<value;
    }
    cout   <<   endl;
    infile.close();
    return   0;  
}


#include "iostream"
#include "str.h"
#include <fstream>
#include <sstream> //用来连接字符串的
using namespace std;

int main()
{

/*      
        char *pVar = NULL;
        cout << strinfo ;
        cin >> strinfo;
        if( strinfo == "winter" )
        cout << "you are winter!"<<endl;
        strinfo += " , Welcome to China!";
        cout << strinfo ;
        string strtmp = "How are you? " + strinfo;
        for(int i = 0 ; i < strtmp.size(); i ++)
        cout<<strtmp<<strtmp.size();    

*/    
        ifstream fin("MyData.txt");
        string str;
        ostringstream osTmp;
        while(getline(fin,str))
        {  
    
        osTmp<<"select enterpriseid from domain where enterpriseid="<<str;
        cout<<str<<endl; //显示出来  
        }  
        cout <<osTmp.str();

}
ostringstream osTmp
osTmp<<"select enterpriseid from domain where enterpriseid="<<enterpriseID<<" and name like'%"<<_defaultConf.defaultDomain<<"' limit 1";
  

作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/874/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!


最后编辑: jackxiang 编辑于2008-3-7 14:36
评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]