M
ma740988
Consider the source:
# include <iostream>
# include <string>
# include <fstream>
# include <vector>
# include <sstream>
using namespace std;
int main()
{
std::fstream InOut( "MyText.txt", std::ios::binary |
std::ios::in | std::ios:
ut | std::ios::app );
if( !InOut )
{
std::cout << "File could not be opened\n";
return EXIT_FAILURE; // Or create it here if you want, etc...
}
const std::string dt (" ....... ");
std::string::size_type sz = dt.size();
InOut << "header" + dt + "0x0\n";
InOut << "data" + dt + "0x100\n";
InOut << "data" + dt + "0x1100\n";
InOut << "header" + dt + "0x2100\n";
InOut << "data" + dt + "0x2200\n";
InOut << "data" + dt + "0x3200\n";
InOut.seekg( std::ios_base::beg );
InOut.clear(); // is this necessary at this point?
std::string Buffer;
while ( std::getline ( InOut, Buffer ) ) // quick look
std::cout << Buffer << std::endl;
typedef std::vector<int> INT_VEC;
INT_VEC values;
std::string line;
//char delim('.');
//while( std::getline( InOut, line, delim ) ) // delimiter wont help
here
// now read file and store all 'the values corresponding to header in
a vector
while( std::getline( InOut, line ) )
{
iss.ignore( sz );
int value ( 0 );
iss >> value;
values.push_back(value);
}
// now tell the user about the values you found (should only find 2,
0 and 0x2100 )
std::cout << " ## for each header - here are your choices ## " <<
std::endl;
// display the values vector .. i.e
// For example: 1) 0
// 2) 0x2100
if ( values.size() ) // display purposes ..
{
std::copy(values.begin(), values.end(),
std:
stream_iterator<int>(std::cout, "\n"));
}
std::cin.get();
return EXIT_SUCCESS;
}
With the latter of the while loops, I search for the text 'header'.
Once found, I ignore the dots following header. Lastly I try to
extract the value from the stream object iss for storage into value.
Doesn't work and I'm not sure what I'm missing?
Thanks in advance
# include <iostream>
# include <string>
# include <fstream>
# include <vector>
# include <sstream>
using namespace std;
int main()
{
std::fstream InOut( "MyText.txt", std::ios::binary |
std::ios::in | std::ios:
if( !InOut )
{
std::cout << "File could not be opened\n";
return EXIT_FAILURE; // Or create it here if you want, etc...
}
const std::string dt (" ....... ");
std::string::size_type sz = dt.size();
InOut << "header" + dt + "0x0\n";
InOut << "data" + dt + "0x100\n";
InOut << "data" + dt + "0x1100\n";
InOut << "header" + dt + "0x2100\n";
InOut << "data" + dt + "0x2200\n";
InOut << "data" + dt + "0x3200\n";
InOut.seekg( std::ios_base::beg );
InOut.clear(); // is this necessary at this point?
std::string Buffer;
while ( std::getline ( InOut, Buffer ) ) // quick look
std::cout << Buffer << std::endl;
typedef std::vector<int> INT_VEC;
INT_VEC values;
std::string line;
//char delim('.');
//while( std::getline( InOut, line, delim ) ) // delimiter wont help
here
// now read file and store all 'the values corresponding to header in
a vector
while( std::getline( InOut, line ) )
{
iss.ignore( sz );
int value ( 0 );
iss >> value;
values.push_back(value);
}
// now tell the user about the values you found (should only find 2,
0 and 0x2100 )
std::cout << " ## for each header - here are your choices ## " <<
std::endl;
// display the values vector .. i.e
// For example: 1) 0
// 2) 0x2100
if ( values.size() ) // display purposes ..
{
std::copy(values.begin(), values.end(),
std:
}
std::cin.get();
return EXIT_SUCCESS;
}
With the latter of the while loops, I search for the text 'header'.
Once found, I ignore the dots following header. Lastly I try to
extract the value from the stream object iss for storage into value.
Doesn't work and I'm not sure what I'm missing?
Thanks in advance