M
Martin =?UTF-8?B?SsO4cmdlbnNlbg==?=
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{document}\n";
string LaTeX_tail = "\end{document\n}";
string current_data_type;
char* valid_data_types[3] = {"Temperature", "Rho*cp", "Cell_energy"};
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_types" ...
then begin conversion... Else: read a new line */
/* valid lines beginn with:
"SCALARS" + spc + |current_data_type| + spc */
/* test: cout read_line; */
/* tex_file[filenumber].tex */
ofstream outfile("tex_file", i, ".tex");
/**********************************
* do the actual conversion here *
**********************************/
outfile << LaTeX_header;
/*
for(unsigned int linenumber=1; linenumber<number_of_lines;
linenumber++)
{
infile >> something;
outfile << converted_something;
}
*/
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
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 <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{document}\n";
string LaTeX_tail = "\end{document\n}";
string current_data_type;
char* valid_data_types[3] = {"Temperature", "Rho*cp", "Cell_energy"};
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_types" ...
then begin conversion... Else: read a new line */
/* valid lines beginn with:
"SCALARS" + spc + |current_data_type| + spc */
/* test: cout read_line; */
/* tex_file[filenumber].tex */
ofstream outfile("tex_file", i, ".tex");
/**********************************
* do the actual conversion here *
**********************************/
outfile << LaTeX_header;
/*
for(unsigned int linenumber=1; linenumber<number_of_lines;
linenumber++)
{
infile >> something;
outfile << converted_something;
}
*/
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