字符串流 stringstream ofstream ifstream

#include<iostream>
#include<sstream>
using namespace std;

int main()
{
    double a,b;
    istringstream is("12.3445 2.3");
    is>>a>>b;                                //这里可以转任意类型
    cout<<"a = "<<a<<endl;
    cout<<"b = "<<b<<endl;

    // 字符串,连接
    string tt ("dddddd");
    stringstream ss ;

    for(int i =0;i<10;i++)
        ss<<tt;

    string out = ss.str().c_str();

    cout<<"b = "<<out <<endl;

    return 0;
}

多个参数字符串连接

#include <jni.h>
#include <string>
#include <sstream>
#include <exception>
#include<iostream>
using namespace std;


inline ostream &_concat(ostream &os){
    return os;
};
template <typename T1, typename... TT>
inline ostream &_concat(ostream &os,const T1 &t1, TT && ... tt){
    os<<t1;
    return _concat(os,tt...);
};

int main()
{
 
    // 字符串,连接
    string tt ("dddddd");
    stringstream ss ;
    //  all to string
    _concat(ss,tt,tt,tt);
    cout<<"out= "<<ss <<endl;
    return 0;
}

 ifstream

读入,矩阵;

0.870841 0.47948 0.108328 -94.9054 

-0.4907 0.861001 0.133756 -117.568 

-0.0291374 -0.169637 0.985076 -1134.12 

0 0 0 1 
	 double matrix[16] = {0};	

 ifstream OpenFile(filename);

	if (OpenFile.fail())
	{
		MITK_INFO << "打开文件错误!" << filename;

		return ret;

	}
	
	int index = 0;
	while (index < 16)
	{
		OpenFile >> matrixArray[index++];
	}

	matrix->DeepCopy(matrixArray);
	OpenFile.close();

ofstream

写入上面矩阵


ofstream fcout(filename);
	if (!fcout) {
		//cout << "File Not Opened" << endl; 
		return;
	}
	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 4; ++j) {
			fcout << m->GetElement(i, j) << " ";
		}
		fcout << "\n\r";
	}
	fcout << "\n\r";
	fcout.close();

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

恋恋西风

up up up

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值