B
BobR
Martin Jørgensen wrote in message
<[email protected]>...
/* """
/*****************************************************/
void convert_data( unsigned int &linenumber,
const unsigned int &number_of_lines,
const ifstream &infile,
const string &cur_ofilename){
""" */
Just thought I'd throw in a little tip here. I noticed you used the arg
'ifstream &infile'.
If you change that to 'istream &' (toss the 'f'), you can pass different
streams to it:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
void MyFunc( std::istream &in ){
std::string temp;
in >> temp; // or, std::getline( in, temp );
std::cout << temp <<std::endl;
return;
}
int main(){
// let user input something
MyFunc( std::cin ); // [1]
// use a 'set' stringstream for testing
std::istringstream MyTest( "I am what I am x 25." );
MyFunc( MyTest );
// send it a file to read
std::ifstream MyFile( "somefile.txt" );
MyFunc( MyFile );
return 0;
} // main()
[1] - I run in a GUI (wxWidgets), so, I'm not *positive* about this use. I
have tested 'std::cout' on an 'ostream&', which worked (output to dbg
debugger in IDE environ.).
Also, you mentioned you wanted to learn more about 'try/catch'. Besides many
good books, a good, free, download is Bruce Eckel's 'Thinking in C++' (vol 1
& 2). Volume 2 has a chapter on 'exceptions'. It should be enough to get you
going.
Get "Thinking in C++", 2nd ed. Volume 1 & 2 by Bruce Eckel
(available for free here. You can buy it in hardcopy too.):
http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html
Enjoy.
<[email protected]>...
/* """
/*****************************************************/
void convert_data( unsigned int &linenumber,
const unsigned int &number_of_lines,
const ifstream &infile,
const string &cur_ofilename){
""" */
Just thought I'd throw in a little tip here. I noticed you used the arg
'ifstream &infile'.
If you change that to 'istream &' (toss the 'f'), you can pass different
streams to it:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
void MyFunc( std::istream &in ){
std::string temp;
in >> temp; // or, std::getline( in, temp );
std::cout << temp <<std::endl;
return;
}
int main(){
// let user input something
MyFunc( std::cin ); // [1]
// use a 'set' stringstream for testing
std::istringstream MyTest( "I am what I am x 25." );
MyFunc( MyTest );
// send it a file to read
std::ifstream MyFile( "somefile.txt" );
MyFunc( MyFile );
return 0;
} // main()
[1] - I run in a GUI (wxWidgets), so, I'm not *positive* about this use. I
have tested 'std::cout' on an 'ostream&', which worked (output to dbg
debugger in IDE environ.).
Also, you mentioned you wanted to learn more about 'try/catch'. Besides many
good books, a good, free, download is Bruce Eckel's 'Thinking in C++' (vol 1
& 2). Volume 2 has a chapter on 'exceptions'. It should be enough to get you
going.
Get "Thinking in C++", 2nd ed. Volume 1 & 2 by Bruce Eckel
(available for free here. You can buy it in hardcopy too.):
http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html
Enjoy.