#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int arr[3][3] = { 1, 1, 1,
2, 2, 2,
3, 3, 3 };
ofstream ofs("test.txt", ios::binary);
const char* data = "33111222333";
string line = data;
ofs.write( line.data(), line.length() );
ofs.close();
char buffer[256];
ifstream ifs("test.txt", ios::binary);
ifs.getline(buffer, sizeof(buffer) );
ifs.close();
string bufferdata = buffer;
int width = bufferdata.at(0) - '0';
int height = bufferdata.at(1) - '0';
int index = 0;
int row = 0, col = 0;
while(1)
{
if( index == width*height )
break;
row = index/width; // Integer division, always rounds down
col = index%width; // Modulus
cout<<"Row:"<<row<<" "<<"Col:"<<col<<endl;
bufferdata.at(index++);
}
return 0;
}
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int arr[3][3] = { 1, 1, 1,
2, 2, 2,
3, 3, 3 };
ofstream ofs("test.txt", ios::binary);
const char* data = "33111222333";
string line = data;
ofs.write( line.data(), line.length() );
ofs.close();
char buffer[256];
ifstream ifs("test.txt", ios::binary);
ifs.getline(buffer, sizeof(buffer) );
ifs.close();
string bufferdata = buffer;
int width = bufferdata.at(0) - '0';
int height = bufferdata.at(1) - '0';
int index = 0;
int row = 0, col = 0;
while(1)
{
if( index == width*height )
break;
row = index/width; // Integer division, always rounds down
col = index%width; // Modulus
cout<<"Row:"<<row<<" "<<"Col:"<<col<<endl;
bufferdata.at(index++);
}
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks