R
robertoviperbr
Hello to everybody.
I have a doubt see the code:
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iterator>
using namespace std;
class Test
{
private:
vector<int>Number;
string szFileNameInput;
string szFileNameOutPut;
static long posx;
...
public:
Test() : Number(15),szFileNameInput(""),szFileNameOutPut(""){};
~Test(){};
int ReadFileInput(const string& file, vector<int>& ref);
int WriteFileOutPut(const string& file, vector<int>& ref);
};
long Test:osx = 0;
This code opens an archive with 126 lines with disordered numbers, for
example:
01 12 45 88 99 35 66
and I am trying to make:
int Test::ReadFileInput(const string& file,vector<int>& ref)
{
try
{
ifstream in(file.c_str());
if(!in) throw string("Error 1: ");
string temp;
in.seekg(input,ios::beg);
getline(in,temp,'\n');
input = in.tellg();
in.close();
in.clear();
istringstream is(temp);
istream_iterator<int>ini(is),fim;
vector<int>num(ini,fim);
copy(num.begin(),num.end(),ref.begin());
sort(ref.begin(),ref.end());
temp.clear();
return 0;
}
catch(string msg)
{
cout<< msg << file<< endl;
cin.get();
exit(1);
}
}
int Test::WriteFileOutput(const string& file,vector<int>& ref)
{
try
{
ofstream off(file.c_str(),ios::app);
if(!off) throw string("Error 2: ");
for(unsigned int i = 0; i < NumerosPorSorteio; i++)
{
off << setfill('0') << setw(2) << ref << " ";
}
off << endl;
off.close();
ref.clear();
return 0;
}
catch(string msg)
{
cout<< msg << file << endl;
cin.get();
exit(1);
}
}
But in no line value "00" exists but it appears after the line number
50.
What I am making of made a mistake?
Thanks a lot for help.
I have a doubt see the code:
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iterator>
using namespace std;
class Test
{
private:
vector<int>Number;
string szFileNameInput;
string szFileNameOutPut;
static long posx;
...
public:
Test() : Number(15),szFileNameInput(""),szFileNameOutPut(""){};
~Test(){};
int ReadFileInput(const string& file, vector<int>& ref);
int WriteFileOutPut(const string& file, vector<int>& ref);
};
long Test:osx = 0;
This code opens an archive with 126 lines with disordered numbers, for
example:
01 12 45 88 99 35 66
and I am trying to make:
int Test::ReadFileInput(const string& file,vector<int>& ref)
{
try
{
ifstream in(file.c_str());
if(!in) throw string("Error 1: ");
string temp;
in.seekg(input,ios::beg);
getline(in,temp,'\n');
input = in.tellg();
in.close();
in.clear();
istringstream is(temp);
istream_iterator<int>ini(is),fim;
vector<int>num(ini,fim);
copy(num.begin(),num.end(),ref.begin());
sort(ref.begin(),ref.end());
temp.clear();
return 0;
}
catch(string msg)
{
cout<< msg << file<< endl;
cin.get();
exit(1);
}
}
int Test::WriteFileOutput(const string& file,vector<int>& ref)
{
try
{
ofstream off(file.c_str(),ios::app);
if(!off) throw string("Error 2: ");
for(unsigned int i = 0; i < NumerosPorSorteio; i++)
{
off << setfill('0') << setw(2) << ref << " ";
}
off << endl;
off.close();
ref.clear();
return 0;
}
catch(string msg)
{
cout<< msg << file << endl;
cin.get();
exit(1);
}
}
But in no line value "00" exists but it appears after the line number
50.
What I am making of made a mistake?
Thanks a lot for help.