-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpgmSave.cpp
More file actions
48 lines (36 loc) · 910 Bytes
/
pgmSave.cpp
File metadata and controls
48 lines (36 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* pgmSave.cpp
*
* Created on: Oct 28, 2013
* Author: Arthur Bousquet
*/
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include "functions.h"
using namespace std;
void pgmSave (string outFile, string tag, unsigned int pgmCols, unsigned int pgmRows, unsigned int pgmMaxval, unsigned int pixels[][1024])
{
string line;
cin.clear();
cout << "Please input the filename to write to [somepicMod.pgm]: ";
getline( cin, line );
if ( line != "" )
outFile = line;
ofstream someFile (outFile.c_str());
if (!someFile.good())
{
cout << "Error accessing output file."<<endl;
return;
}
someFile << tag << '\n' << pgmCols << " " << pgmRows << '\n' << pgmMaxval << '\n';
for ( unsigned int j = 0; j < pgmRows; j++ )
{
for ( unsigned int i = 0; i < pgmCols; i++ )
someFile << pixels[j][i] << " ";
someFile << '\n';
}
someFile.close();
return;
}