需要有关我的转换工具的帮助... [英] Need help with my conversion utility...
问题描述
我在春天有一门C ++入门课程,并且几个月内没有用
C ++编程现在(但我已经用C编程了,因为
1月)。所以我决定在C ++中使用转换实用程序,然后才忘记
所有内容。但它没有编译:
------------
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:
------------
cat export_tex .C
cat export_tex.C
#include< iostream>
#include< fstream>
#include<字符串>
使用命名空间std;
/ *********************** ************************** *
* *
*此程序从中获取数据一些.vtk *
*输入文件并将它们导出为.tex格式*
* *
******* ****************************************** /
int main()
{
/ *将包含LaTeX序言等* /
字符串LaTeX_header =" test,bla.bla。 .. \ n\begin {document} \ n" ;;
string LaTeX_tail =" \end {document\\\
}" ;;
string current_data_type;
char * valid_data_types [3] = {" Temperature"," Rho * cp"," Cell_energy"};
string read_line;
unsigned int filenumber; / *当前数据文件号* /
unsigned int number_of_lines; / *告诉我们有多少数据行* /
/ *************************** *********************** **********
*转换循环 - 只要数据继续 - 存在文件*
************************************** ************ ********** /
for(unsigned int i = 0; i< 999; i ++)< br $>
{
ifstream infile(" file",i," .vtk"); / * file [filenumber] .vtk * /
if(infile)
{
infile> read_line;
/ * ???如果read_line ==其中一个valid_data_types ...
然后开始转换...其他:读一个新行* /
/ *有效行开始于:
"标量" + spc + | current_data_type | + spc * /
/ * test:cout read_line; * /
/ * tex_file [filenumber] .tex * /
ofstream outfile(" tex_file",i," .tex"); < br $> b $ b / **********************************
*在这里进行实际转换*
********************************** /
outfile<< LaTeX_header;
/ *
for(unsigned int linenumber = 1; linenumber< number_of_lines;
linenumber ++)
{
infile>某事;
outfile<< converted_something;
}
* /
outfile<< LaTeX_tail;
}
如果(!infile)/ *无法打开文件?然后结束* /
休息;
}
cout<< filenumber + 1<< "编写的.tex文件数量 << endl<< endl;
返回0;
}
------------
正如你所看到的那样,它可能非常C风格而且不是很好的C ++风格,因为我用b
$ b做了我的单身汉项目(和这个转换实用程序)是我的bs.c项目的延续
)。
第一步:如何进行编译?建议是最受欢迎的...
当我尝试编译时,我收到很多奇怪的东西......例如:
/ usr / include / c ++ / 4.1.0 / i586-suse-linux / bits / c ++ config.h:43:错误:预期
构造函数,析构函数或类型转换之前的?? namespacea ??
/usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:47:错误:
a ?? __ gnu_debug_defa ??不是命名空间名称
/usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:47:错误:预期
namespace-name之前?? ?? a ??令牌
......等等...
祝你好运
Martin J ?? rgensen
-
---------------------------------- -----------------------------------------
主页of Martin J ?? rgensen - http://www.martinjoergensen.dk
#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 a??namespacea??
/usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:47: error:
a??__gnu_debug_defa?? is not a namespace-name
/usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:47: error: expected
namespace-name before a??;a?? token
...... etc. etc...
Best regards
Martin J??rgensen
--
---------------------------------------------------------------------------
Home of Martin J??rgensen - http://www.martinjoergensen.dk
推荐答案
这好像来自编译器本身,这意味着有
出了点问题。只是一个疯狂的猜测;您可能会尝试以不同的顺序包含
''#include'。如果这不起作用安装另一个
版本的g ++。
问候,Ron AF Greve
http://moonlit.xs4all.nl
" Martin J?rgensen" < ho ********** @ hotmail.comwrote in message
news:45 ******************** *@dread12.news.tele.dk。 ..
Hi,
Well this seems to come from the compiler itself, this means there is
something wrong with it. Just a wild guess; you might try to include the
''#include'' s in a different order. If that doesn''t work install another
version of g++.
Regards, Ron AF Greve
http://moonlit.xs4all.nl
"Martin J?rgensen" <ho**********@hotmail.comwrote in message
news:45*********************@dread12.news.tele.dk. ..
我在春天有一个C ++入门课程并且没有编程在
C ++中已经有几个月了(但我已经用C编程了,因为
1月)。所以我决定在C ++中使用转换实用程序,然后才忘记
所有内容。但它没有编译:
------------
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:
------------
> cat export_tex.C
>cat export_tex.C
#include< iostream>
#include< fstream>
#include < string>
使用命名空间std;
/ ***************** ********************************
* *
*此程序从一些.vtk *
*输入文件中获取数据,并将它们导出为.tex格式*
* *
* ********** / < br $> b
$ b int main()
{
/ *将包含LaTeX序言等* /
string LaTeX_header =" test,bla.bla ... \ n\begin {document} \ n" ;;
string LaTeX_tail =" \end {document\\\
}" ;
string current_data_type;
char * v alid_data_types [3] = {" Temperature"," Rho * cp"," Cell_energy"};
string read_line;
unsigned int filenumber ; / *当前数据文件号* /
unsigned int number_of_lines; / *告诉我们有多少数据行* /
/ *************************** *********************** **********
*转换循环 - 只要数据继续 - 存在文件*
************************************** ************ ********** /
for(unsigned int i = 0; i< 999; i ++)< br $>
{
ifstream infile(" file",i," .vtk"); / * file [filenumber] .vtk * /
if(infile)
{
infile> read_line;
/ * ???如果read_line ==其中一个valid_data_types ...
然后开始转换...其他:读一个新行* /
/ *有效行开始于:
"标量" + spc + | current_data_type | + spc * /
/ * test:cout read_line; * /
/ * tex_file [filenumber] .tex * /
ofstream outfile(" tex_file",i," .tex");
/ **********************************
*在这里进行实际转换*
******************************* *** /
outfile<< LaTeX_header;
/ *
for(unsigned int linenumber = 1; linenumber< number_of_lines;
linenumber ++)
{
infile>某事;
outfile<< converted_something;
}
* /
outfile<< LaTeX_tail;
}
如果(!infile)/ *无法打开文件?然后结束* /
休息;
}
cout<< filenumber + 1<< "编写的.tex文件数量 << endl<<结束;
返回0;
}
------------
正如你所看到的那样,它可能非常C风格而且不是很好的C ++风格,因为
我
用C完成了我的学士学位项目(这个转换实用程序是一个
延续
我的bs.c项目)。
第一步:如何进行编译?建议是最受欢迎的...
当我尝试编译时,我收到很多奇怪的东西......例如:
/ usr / include / c ++ / 4.1.0 / i586-suse-linux / bits / c ++ config.h:43:错误:
预期
构造函数,析构函数,或''命名空间'之前键入转换'
/usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:47:错误:
''__ gn_debug_def''不是命名空间名称
/usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h: 47:错误:
预期
命名空间名称'';'''令牌
.....等等...
祝你好运
Martin J?rgensen
-
- -------------------------------------------------- -----------------------
Martin J?rgensen的家 - http://www.martinjoergensen.dk
>
等一下,您的文件以.cc结束或不结束?确保你用
g ++而不是gcc编译它。
问候,Ron AF Greve
http://moonlit.xs4all.nl
Moonlit < news moonlit xs4all nlwrote in message
news:45 ********************** @ news.xs4all.nl ...
Hi,
Wait a minute, your file ends with .cc or not? Make sure you compile it with
g++ and not gcc.
Regards, Ron AF Greve
http://moonlit.xs4all.nl
"Moonlit" <news moonlit xs4all nlwrote in message
news:45**********************@news.xs4all.nl...
这好像来自编译器本身,这意味着有
有点不对劲。只是一个疯狂的猜测;您可能会尝试以不同的顺序包含
''#include'。如果这不起作用安装另一个
版本的g ++。
问候,Ron AF Greve
http://moonlit.xs4all.nl
" Martin Ĵrgensen"?; < ho ********** @ hotmail.comwrote in message
news:45 ******************** *@dread12.news.tele.dk。 ..
Hi,
Well this seems to come from the compiler itself, this means there is
something wrong with it. Just a wild guess; you might try to include the
''#include'' s in a different order. If that doesn''t work install another
version of g++.
Regards, Ron AF Greve
http://moonlit.xs4all.nl
"Martin J?rgensen" <ho**********@hotmail.comwrote in message
news:45*********************@dread12.news.tele.dk. ..
>
我在春天有一个C ++入门课程并且没有编程
在C ++中已经有几个月了(但是自从1月份以来我已用C语言编程)。所以我决定用C ++做我的转换实用程序,然后才忘记
一切。但它没有编译:
------------
>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:
------------
>> cat export_tex .C
>>cat export_tex.C
#include< iostream>
#include< fstream>
#include< string>
使用命名空间std;
/ *************************************** ********* *
* *
*此程序从一些.vtk *
*输入文件中获取数据并将其导出为.tex-format *
* *
***************************************** **** ** /
int main()
/ *将包含LaTeX序言等* /
字符串LaTeX_header =" test,bla。 bla ... \ n \ begin {document} \\\
" ;;
string LaTeX_tail =" \end {document\\\
}" ;;
string current_data_type;
char * valid_data_types [3] = {" Temperature"," Rho * cp"," Cell_energy"};
str read_line;
unsigned int filenumber; / *当前数据文件号* /
unsigned int number_of_lines; / *告诉我们有多少数据行* /
/ ******************************* ******************* **********
*转换循环 - 只要数据文件存在就继续*
************************************************** ********** /
for(unsigned int i = 0; i< 999; i ++)
ifstream infile(" ; file",i," .vtk"); / * file [filenumber] .vtk * /
if(infile)
{
infile> read_line;
/ * ???如果read_line ==其中一个valid_data_types ......然后开始转换...其他:读一个新行* /
/ *有效行开始于:
" SCALARS" + spc + | current_data_type | + spc * /
/ * test:cout read_line; * /
/ * tex_file [filenumber] .tex * /
ofstream outfile(" tex_file",i," .tex");
/ ********************************** *
*在这里进行实际转换*
* ********************************* /
outfile<< LaTeX_header;
/ *
for(unsigned int linenumber = 1; linenumber< number_of_lines;
linenumber ++)
{
infile> something;
outfile<< converted_something;
}
* /
outfile<< LaTeX_tail;
}
如果(!infile)/ *无法打开文件?然后完成* /
休息;
}
cout<< filenumber + 1<< "编写的.tex文件数量 << endl<< endl;
返回0;
}
------------
如你所见可能非常C风格,而且不是很好的C ++风格,
因为我用C做了我的单身汉项目(而且这个转换实用程序是
延续
我的bs.c项目。
第一步:如何编译?建议是最受欢迎的...
当我尝试编译时,我收到很多奇怪的东西......例如:
/usr/include/c++/4.1。 0 / i586-suse-linux / bits / c ++ config.h:43:错误:
期望
构造函数,析构函数或''命名空间'之前的类型转换'
/ usr / include / c ++ / 4.1.0 / i586-suse-linux / bits / c ++ config.h:47:错误:
''__ nuu_debug_def''不是名称空间名称
/ usr / include /c++/4.1.0/i586-suse-linux/bits/c++config.h:47:错误:
期望
名称空间名称'';'''令牌
。 ......等等...
最好的问候
Martin J?rgensen
-
-------- -------------------------------------------------- -----------------
Martin J?rgensen的家 - http://www.martinjoergensen.dk
cat export_tex.C
cat export_tex.C
....
....
第一步:如何制作这个编译?建议最受欢迎...
First step: How can I make this compile? Suggestions are most welcome...
它抱怨使用,这是特定于C ++的。
我的猜测 - 将文件名更改为.CC或.cc或.cpp或类似
。至少我使用过的几个编译器都有一个启发式,
检查文件名并在C模式或C ++模式下编译。并确保你使用编译器的C ++版本(g ++而不是gcc)。
我尝试在VS中编译,它抱怨,但不是那个。
Michael
It''s complaining about the word "using," which is C++ specific.
My guess - change the filename to .CC or .cc or .cpp or something like
that. At least a couple of compilers I''ve used have a heuristic that
checks filename and compiles in C mode or C++ mode depending. And be
sure you''re using the C++ version of the compiler (g++ instead of gcc).
I tried compiling in VS, and it complains, but not about that.
Michael
这篇关于需要有关我的转换工具的帮助...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!