visual studio 2012 写入文件里面
来源:互联网 发布:淘宝蚂蚁花呗在哪开通 编辑:程序博客网 时间:2024/05/22 03:44
C++将矩阵存到.txt文件, 使用 FILE 或 ofstream,在MFC编写中会用到CStdioFile
1、使用FILE
int main(){
int i, j ;
cv::Mat my_mat( 20, 20, CV_32FC2, cv::Scalar::all(0) ) ;
FILE *fp ;
fp = fopen( "myfile.txt", "w" ) ;
for(i=0; i<my_mat.rows; i++){
for(j=0; j<my_mat.cols; j++){
fprintf(fp, "%3.0f", my_mat.at<float>(i,j) ) ; // the data type should be matched.
// the same as that of my_mat
}
fprintf( fp, "\n" ) ;
}
fclose( fp ) ;
return 1 ;
}
2、使用 ofstream来保存文件
// 这里假设需要保存图像 img_gray 的灰度值 到文件夹
std::string fileName = "val_img.txt" ;
std::ofstream outfile( fileName.c_str() ) ; // file name and the operation type.
int i, j ;
for( i=0; i<img_gray.rows; i++ ){
for( j=0; j<img_gray.cols; j++ )
outfile << (int) img_gray.at<uchar>(i,j) << " " ; // note the uchar, be changed to int type.
outfile << std::endl ; // a newline after storing all the values of a line of the img
}
outfile.close() ;
3、使用CStdioFile来保存文件
CStdioFile f1;
f1.Open("D:\\a.txt", CFile::modeCreate | CFile::modeWrite|CFile::typeText);
f1.WriteString(result);
f1.Close();
- visual studio 2012 写入文件里面
- 为什么我每次打开visual studio 2005 的时候里面的asp文件都会自动打开???
- Visual Studio 中的文件
- Visual Studio 文件
- Visual Studio自动定位文件
- Visual Studio中的ncb文件
- Visual Studio 2012 Update 3 (KB2707250) 离线安装 文件下载
- Visual Studio 2012生成被外部调用的dll文件
- 修改Visual Studio Express 2012新建C++文件编码
- Visual Studio 2012以后无法保存只读文件的问题
- android studio logcat写入到指定文件
- Visual Studio里面的搜索和浏览的一些技巧
- Visual Studio里面的搜索和浏览的一些技巧
- catalog items view ---在Visual studio 2008里面的位置
- Visual Studio里面的搜索和浏览的一些技巧
- Visual Studio里面的搜索和浏览的一些技巧
- Visual Studio 2012
- 吐槽Visual Studio 2012
- Java总结篇系列:Java多线程(二)
- CentOS 6.8 安装 Docker
- css3
- 在jsp页面获取el表达式的值
- 提高网站转化率——页面停留时间与网站停留时间
- visual studio 2012 写入文件里面
- mapreduce实现wordcount
- linux 休眠与唤醒
- Window向阿里云ESC传送文件(Centos)
- form表单提交多个name值,mybatis一条insert
- 判断PC端还是移动端,加载不同JS库
- ExecutorService 的理解与使用
- supervisor(一)基础篇
- 对Timer改进,不需要再 viewWillDisappear 中释放