#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();