Hi,
I've had a introductory C++ course in the spring and haven't programmed in
C++ for a couple of months now (but I have been programmed in C since
january). So I decided to do my conversion utility in C++, before I forget
everything. But it doesn't compile:
------------
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
/*************** *************** *************** ****
* *
* This program takes data from some .vtk *
* input-files and exports them to .tex-format *
* *
*************** *************** *************** ****/
int main()
{
/* will contain LaTeX preamble etc */
string LaTeX_header = "test, bla.bla... \n\begin{docume nt}\n";
string LaTeX_tail = "\end{document\ n}";
string current_data_ty pe;
char* valid_data_type s[3] = {"Temperatur e", "Rho*cp", "Cell_energ y"};
string read_line;
unsigned int filenumber; /* current data file number */
unsigned int number_of_lines ; /* tells how many data lines follows */
/*************** *************** *************** ***************
* conversion loop - continue as long as data-files exists *
*************** *************** *************** ***************/
for(unsigned int i=0; i<999; i++)
{
ifstream infile("file", i, ".vtk"); /* file[filenumber].vtk */
if( infile )
{
infile >read_line;
/* ??? if read_line == one of the "valid_data_typ es" ...
then begin conversion... Else: read a new line */
/* valid lines beginn with:
"SCALARS" + spc + |current_data_t ype| + spc */
/* test: cout read_line; */
/* tex_file[filenumber].tex */
ofstream outfile("tex_fi le", i, ".tex");
/*************** *************** ****
* do the actual conversion here *
*************** *************** ****/
outfile << LaTeX_header;
/*
for(unsigned int linenumber=1; linenumber<numb er_of_lines;
linenumber++)
{
infile >something;
outfile << converted_somet hing;
}
*/
outfile << LaTeX_tail;
}
if( ! infile ) /* can't open file? Then finish */
break;
}
cout << filenumber+1 << " number of .tex files written" << endl << endl;
return 0;
}
------------
As you see it's probably very much C-style and not very good C++-style, as I
did my bachelor project in C (and this conversion utility is a continuation
of my bs.c project).
First step: How can I make this compile? Suggestions are most welcome...
I get a lot of strange things when I try to compile... Such as:
/usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:43: error: expected
constructor, destructor, or type conversion before ‘namespace’
/usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:47: error:
‘__gnu_debug_ def’ is not a namespace-name
/usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:47: error: expected
namespace-name before ‘;’ token
...... etc. etc...
Best regards
Martin Jørgensen
--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
I've had a introductory C++ course in the spring and haven't programmed in
C++ for a couple of months now (but I have been programmed in C since
january). So I decided to do my conversion utility in C++, before I forget
everything. But it doesn't compile:
------------
cat export_tex.C
#include <fstream>
#include <string>
using namespace std;
/*************** *************** *************** ****
* *
* This program takes data from some .vtk *
* input-files and exports them to .tex-format *
* *
*************** *************** *************** ****/
int main()
{
/* will contain LaTeX preamble etc */
string LaTeX_header = "test, bla.bla... \n\begin{docume nt}\n";
string LaTeX_tail = "\end{document\ n}";
string current_data_ty pe;
char* valid_data_type s[3] = {"Temperatur e", "Rho*cp", "Cell_energ y"};
string read_line;
unsigned int filenumber; /* current data file number */
unsigned int number_of_lines ; /* tells how many data lines follows */
/*************** *************** *************** ***************
* conversion loop - continue as long as data-files exists *
*************** *************** *************** ***************/
for(unsigned int i=0; i<999; i++)
{
ifstream infile("file", i, ".vtk"); /* file[filenumber].vtk */
if( infile )
{
infile >read_line;
/* ??? if read_line == one of the "valid_data_typ es" ...
then begin conversion... Else: read a new line */
/* valid lines beginn with:
"SCALARS" + spc + |current_data_t ype| + spc */
/* test: cout read_line; */
/* tex_file[filenumber].tex */
ofstream outfile("tex_fi le", i, ".tex");
/*************** *************** ****
* do the actual conversion here *
*************** *************** ****/
outfile << LaTeX_header;
/*
for(unsigned int linenumber=1; linenumber<numb er_of_lines;
linenumber++)
{
infile >something;
outfile << converted_somet hing;
}
*/
outfile << LaTeX_tail;
}
if( ! infile ) /* can't open file? Then finish */
break;
}
cout << filenumber+1 << " number of .tex files written" << endl << endl;
return 0;
}
------------
As you see it's probably very much C-style and not very good C++-style, as I
did my bachelor project in C (and this conversion utility is a continuation
of my bs.c project).
First step: How can I make this compile? Suggestions are most welcome...
I get a lot of strange things when I try to compile... Such as:
/usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:43: error: expected
constructor, destructor, or type conversion before ‘namespace’
/usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:47: error:
‘__gnu_debug_ def’ is not a namespace-name
/usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:47: error: expected
namespace-name before ‘;’ token
...... etc. etc...
Best regards
Martin Jørgensen
--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
Comment