C++读取txt数据

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main()
{
    char buffer[255];
    long double j;
    int t;
    string t1, t2;
    fstream out;
    out.open("rpts.txt", ios::in);
    cout << "rpts.txt" << " 的内容如下:" << endl;
    while (!out.eof())
    {
        out.getline(buffer, 256, '\n');//getline(char *,int,char) 表示该行字符达到256个或遇到换行就结束
        cout << buffer << endl;
        t1.assign(buffer);  //将buffer字符串赋给t1
        int loc = t1.find('\t',0);  //从头查找空格符,返回空格符的位置 
        t = t1.length();
        t2 = t1.substr(0, loc); //将t1的[0]~[loc]的数据复制给t2
        j =atof(t2.c_str()) ; //将t2的字符转换为数据
        if(j != 0)
        cout << j << endl;

        t2 = t1.substr(loc+1, t-loc);
        j = atof(t2.c_str());
        if (j != 0)
        cout << j << endl;
    }
    out.close();
    cin.get();//cin.get() 是用来读取回车键的,如果没这一行,输出的结果一闪就消失了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值