使用g ++编译问题 [英] Compiling problems with g++

查看:75
本文介绍了使用g ++编译问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我正在尝试编译别人的代码而且我使用

g ++ 3.3编译器来解决编译问题。基本上,在编译下面的代码时,我得到了这个错误信息:


parsefcns.cc:在函数`void get_token(std :: ifstream *, char **)'':

parsefcns.cc:57:错误:无法转换`std :: basic_string< char,

std :: char_traits< char>,std ::分配器<炭> >''到'char *''在

分配

make:*** [parsefcns.o]错误1


我不知道C ++,我想知道是否有一个善良的人愿意帮助我解决这个问题。

提前谢谢。

Arturo


............................... ............

#include< fstream>

#include< sstream>

#include < cctype>

#include< cstring>

#include< iostream>


using namespace std;

使用std :: ifstream;

使用std :: ostringstream;


void get_token(std :: ifstream * f_stream,char * * ch_ptr)

{

char ch;

std :: ostringstream buffer;


while ((f_stream-> get(ch))&&

(!isspace(ch))&&

(!f_stream-> eof( )))

{

buffer<< ch;

}

buffer<< ''\''';

(* ch_ptr)= buffer.str(); //这是给出汇编的行

问题

//返回ch;

f_stream-> seekg(-1,std :: ios :: cur);

}

.............等。

Hello everyone. I am trying to compile someone else code and I am
stuck with compilation problems using
the g++ 3.3 compiler. Basically, when compiling the following code, I
get this error message:

parsefcns.cc: In function `void get_token(std::ifstream*, char**)'':
parsefcns.cc:57: error: cannot convert `std::basic_string<char,
std::char_traits<char>, std::allocator<char> >'' to `char*'' in
assignment
make: *** [parsefcns.o] Error 1

I don''t know C++ and I was wondering if there was a kind soul willing
to help me in solving this problem.
Thanks in advance.
Arturo

...........................................
#include <fstream>
#include <sstream>
#include <cctype>
#include <cstring>
#include <iostream>

using namespace std;
using std::ifstream;
using std::ostringstream;

void get_token(std::ifstream *f_stream, char **ch_ptr)
{
char ch;
std::ostringstream buffer;

while( (f_stream->get(ch)) &&
(!isspace(ch)) &&
(!f_stream->eof()) )
{
buffer << ch;
}
buffer << ''\0'';
(*ch_ptr) = buffer.str(); // This is the line giving compilation
problems
// return ch;
f_stream->seekg(-1, std::ios::cur);
}
.............etc.

推荐答案



" Arturo DiDonna" < AR ************ @ yahoo.it>在消息中写道

新闻:ba ************************** @ posting.google.c om ...

"Arturo DiDonna" <ar************@yahoo.it> wrote in message
news:ba**************************@posting.google.c om...
大家好。我正在尝试编译别人的代码,并且我使用g ++ 3.3编译器来解决编译问题。基本上,在编译以下代码时,我收到此错误消息:

parsefcns.cc:在函数`void get_token(std :: ifstream *,char **)'':
parsefcns.cc:57:错误:无法转换`std :: basic_string< char,
std :: char_traits< char> ;,std :: allocator< char> >''到'char *''在
作业中
make:*** [parsefcns.o]错误1

我不知道C ++而我是想知道是否有一个善良的灵魂愿意帮助我解决这个问题。
提前致谢。
Arturo

......... .................................
#include< fstream>
#include< ; sstream>
#include< cctype>
#include< cstring>
#include< iostream>

使用命名空间std;


这个指令..

使用std :: ifstream;
使用std :: ostringstream;


...不需要这两个声明。

void get_token(std :: ifstream * f_stream,char ** ch_ptr)


const char ** ch_ptr

{
char ch;
std :: ostringstream buffer;

while(( f_stream-> get(ch))&&
(!isspace(ch))&&
(!f_stream-> eof()))
{
buffer<< ch;
}
缓冲区<< ''\''';
(* ch_ptr)= buffer.str(); //这是给出编译的行
问题


* ch_ptr = buffer.str()。c_str();

//返回ch ;
f_stream-> seekg(-1,std :: ios :: cur);


这里更好地检查成功/失败。


}
............等。
Hello everyone. I am trying to compile someone else code and I am
stuck with compilation problems using
the g++ 3.3 compiler. Basically, when compiling the following code, I
get this error message:

parsefcns.cc: In function `void get_token(std::ifstream*, char**)'':
parsefcns.cc:57: error: cannot convert `std::basic_string<char,
std::char_traits<char>, std::allocator<char> >'' to `char*'' in
assignment
make: *** [parsefcns.o] Error 1

I don''t know C++ and I was wondering if there was a kind soul willing
to help me in solving this problem.
Thanks in advance.
Arturo

..........................................
#include <fstream>
#include <sstream>
#include <cctype>
#include <cstring>
#include <iostream>

using namespace std;
This directive..
using std::ifstream;
using std::ostringstream;
... obviates the need for these two declarations.

void get_token(std::ifstream *f_stream, char **ch_ptr)
const char **ch_ptr
{
char ch;
std::ostringstream buffer;

while( (f_stream->get(ch)) &&
(!isspace(ch)) &&
(!f_stream->eof()) )
{
buffer << ch;
}
buffer << ''\0'';
(*ch_ptr) = buffer.str(); // This is the line giving compilation
problems
*ch_ptr = buffer.str().c_str();
// return ch;
f_stream->seekg(-1, std::ios::cur);
Better check for success/failure here.

}
............etc.




-Mike



-Mike


Arturo DiDonna写道:
Arturo DiDonna wrote:
...
void get_token(std :: ifstream * f_stream,char ** ch_ptr)
{
char ch;
std :: ostringstream buffer;

while( (f_stream-> get(ch))&&
(!isspace(ch))&&
(!f_stream-> eof()))
{
buffer<< ch;
}
缓冲区<< ''\''';
(* ch_ptr)= buffer.str(); //这是给出编译的行
问题
...
void get_token(std::ifstream *f_stream, char **ch_ptr)
{
char ch;
std::ostringstream buffer;

while( (f_stream->get(ch)) &&
(!isspace(ch)) &&
(!f_stream->eof()) )
{
buffer << ch;
}
buffer << ''\0'';
(*ch_ptr) = buffer.str(); // This is the line giving compilation
problems




''std :: ostringstream :: str()''的返回类型是''std: :string'',你是

试图将这个值赋给'char *''类型的对象。显然,

这是一个错误。


无论如何,这不行。看来你正试图将一个

指针返回给一个在函数退出时将被销毁的对象。什么

你想要实现吗?


-

祝你好运,

Andrey Tarasevich



Return type of ''std::ostringstream::str()'' is ''std::string'' and you are
trying to assign this value to an object of type ''char*''. Obviously,
this is an error.

Anyway, this can''t work. It appears that you are trying to return a
pointer to an object that will be destroyed when function exits. What
are you trying to implement?

--
Best regards,
Andrey Tarasevich




" Arturo DiDonna" < AR ************ @ yahoo.it>在消息中写道

新闻:ba ************************** @ posting.google.c om ...

"Arturo DiDonna" <ar************@yahoo.it> wrote in message
news:ba**************************@posting.google.c om...
大家好。我正在尝试编译别人的代码,并且我使用g ++ 3.3编译器来解决编译问题。基本上,在编译以下代码时,我收到此错误消息:

parsefcns.cc:在函数`void get_token(std :: ifstream *,char **)'':
parsefcns.cc:57:错误:无法转换`std :: basic_string< char,
std :: char_traits< char> ;,std :: allocator< char> >''到'char *''在
作业中
make:*** [parsefcns.o]错误1

我不知道C ++而我是想知道是否有一个善良的灵魂愿意帮助我解决这个问题。
提前致谢。
Arturo

......... .................................
#include< fstream>
#include< ; sstream>
#include< cctype>
#include< cstring>
#include< iostream>

使用命名空间std;
使用std :: ifstream;
使用std :: ostringstream;

void get_token(std :: ifstream * f_stream,char ** ch_ptr)
{
char ch;
std :: ostringstream buffer;

while((f_stream-> get(ch))&&
(!isspace(ch))&&& br />(!f_stream-> eof()))
{
缓冲区<< ch;
}
缓冲区<< ''\''';
(* ch_ptr)= buffer.str(); //这是给编译
问题的一行
//返回ch;
f_stream-> seekg(-1,std :: ios :: cur);
}
............等。
Hello everyone. I am trying to compile someone else code and I am
stuck with compilation problems using
the g++ 3.3 compiler. Basically, when compiling the following code, I
get this error message:

parsefcns.cc: In function `void get_token(std::ifstream*, char**)'':
parsefcns.cc:57: error: cannot convert `std::basic_string<char,
std::char_traits<char>, std::allocator<char> >'' to `char*'' in
assignment
make: *** [parsefcns.o] Error 1

I don''t know C++ and I was wondering if there was a kind soul willing
to help me in solving this problem.
Thanks in advance.
Arturo

..........................................
#include <fstream>
#include <sstream>
#include <cctype>
#include <cstring>
#include <iostream>

using namespace std;
using std::ifstream;
using std::ostringstream;

void get_token(std::ifstream *f_stream, char **ch_ptr)
{
char ch;
std::ostringstream buffer;

while( (f_stream->get(ch)) &&
(!isspace(ch)) &&
(!f_stream->eof()) )
{
buffer << ch;
}
buffer << ''\0'';
(*ch_ptr) = buffer.str(); // This is the line giving compilation
problems
// return ch;
f_stream->seekg(-1, std::ios::cur);
}
............etc.




如何在不了解C ++的情况下管理所有这些代码?


无论如何代码是错误的,但是修复是什么并不清楚,因为你不知道C ++ b你也不知道C ++。猜测我会说代码是

意味着使用ostrstream而不是ostringstream,并且< strstream>不是< sstream>,

至少会让它编译成我认为。


john



How did you manage all this code without knowing C++?

Anyway the code is wrong but what the fix is isn''t clear, and since you
don''t know C++ you can help either. At a guess I would say that the code is
meant to use ostrstream not ostringstream, and <strstream> not <sstream>,
that would make it compile at least I think.

john


这篇关于使用g ++编译问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆