473,388 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Compiling problems with g++

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.
Jul 22 '05 #1
11 3153

"Arturo DiDonna" <ar************@yahoo.it> wrote in message
news:ba**************************@posting.google.c om...
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
Jul 22 '05 #2
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;
}
buffer << '\0';
(*ch_ptr) = buffer.str(); // This is the line giving compilation
problems


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

Jul 22 '05 #3

"Arturo DiDonna" <ar************@yahoo.it> wrote in message
news:ba**************************@posting.google.c om...
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.


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
Jul 22 '05 #4
John Harrison wrote:

"Arturo DiDonna" <ar************@yahoo.it> wrote in message
news:ba**************************@posting.google.c om...
Hello everyone. I am trying to compile someone else code

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

Clearer now?

Brian Rodenborn
Jul 22 '05 #5
> while( (f_stream->get(ch)) &&
(!isspace(ch)) &&
(!f_stream->eof()) ) Your code here has problems, should be

while( (f_stream->get(ch)) &&
(!isspace(ch)) )
(*ch_ptr) = buffer.str(); // This is the line giving compilation

Shoudle be

(*ch_ptr) == buffer.str().c_str();
Jul 22 '05 #6
> (*ch_ptr) = buffer.str(); // This is the line giving compilation
After I post the replay as
(*ch_ptr) = buffer.str().c_str();


I got some feeling:
1) buffer is "stack", so buffer.str() is "stack"
2) convert const char* --> char*
So the programming is so error-prone, you never need to fixed it.
Just kick it out,
and find some good one....
Jul 22 '05 #7
"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<1I*******************@newsread1.news.pas.ear thlink.net>...
buffer << '\0';
(*ch_ptr) = buffer.str(); // This is the line giving compilation
problems


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

How can that possibly produce a useful result? 'ch_ptr' is obviously
an output parameter, but the buffer will no longer exist after this
function returns.
But I can't even begin to guess what it should be...other than
something fairly questionable like:

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

Dylan
Jul 22 '05 #8

"teahouse todd" <xu*********@mail.zte.com.cn> wrote in message
news:7d**************************@posting.google.c om...
while( (f_stream->get(ch)) &&
(!isspace(ch)) &&
(!f_stream->eof()) )

Your code here has problems, should be

while( (f_stream->get(ch)) &&
(!isspace(ch)) )
(*ch_ptr) = buffer.str(); // This is the line giving compilation

Shoudle be

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


That doesn't work. It might make the code compile but it will surely crash
when it runs since the memory pointed to by *ch_ptr will have been deleted.

john
Jul 22 '05 #9
Many thanks to all of you who answered my question. I tried first Mike
Wahler suggestion and it worked like charm! Thanks again, Mike.
Unfortunately, the compiler moved past this error just to find some
more... Here is the error message I get now from the following code :

parameters.cc: In constructor `Parameters::Parameters()':
parameters.cc:99: error: cannot convert `std::basic_string<char,
std::char_traits<char>, std::allocator<char> >' to `char*' in
assignment
make: *** [parameters.o] Error 1

#include <cstdlib>
#include <stdio.h>
#include <cctype>
#include <fstream>
#include <cstring>
#include <sstream>

#include "parameters.h"
#include "parsefcns.h"
#include "dlListADT.h"
#include "dlListADT.cc"

using namespace std;

Parameters::Parameters() {
int i;

patt_len = 10;
alph_size = 4;
min_wt = -2.5;
max_wt = 2.5;
step = 3.0;
decay = 0.9417;
momentum = 0.0;

// &&& Begin: Initialization of parameters for second site.
patt_len2 = 10;
initial_wts_factor2 = 0.5;
min_wt2 = -2.5;
max_wt2 = 2.5;
step2 = 3.0;
decay2 = 0.9417;
momentum2 = 0.0;
begin_word2 = NULL;
data2_file = NULL;
weights_file2 = NULL;
energy_file2 = NULL;
max_dist_bw_sites = 0;
search_direction = 0;
// &&& End: Initialization of parameters for second site.

num_sites_sampled = 10000;
sites_per_seq = 1;
comp_flag = 0;
clip_flag = 1;
format_spec = 0;
iters = 2000;
report_interval = 200;
initial_wts_factor = 0.5;
training_runs = 1;
random_num_seed = 17;
partition_option = 1;
begin_word = NULL;
alphabet_file = NULL;
data1_file = NULL; // manditory file
weights_file = NULL;
energy_file = NULL;
param_file = NULL;
std::ostringstream buffer;

usage = buffer.str(); // This line is giving the error message

registry = new int[SWITCHES];
for(i=0;i<SWITCHES;i++) registry[i] = 0;
}
...................................

To make matter even worse, if I comment out the previous error line, I
get another error message from the compiler.

sequenceset.cc: In member function `virtual int
SeqFileReaderObj::read_chunk_of_sequence(int, std::ifstream*,
char**)':
sequenceset.cc:923: error: `pcount' undeclared (first use this
function)
sequenceset.cc:923: error: (Each undeclared identifier is reported
only once
for each function it appears in.)

I report only the code snippet giving the problem (I hope it will
suffice):

........................
int SeqFileReaderObj::read_chunk_of_sequence(int size, std::ifstream
*f_stream,
char **ch_ptr)
{
char ch;
std::ostringstream buffer;

while((f_stream->get(ch)) && (ch != Seq_Delim) && (buffer.pcount() <
size) ) //This line generated the compiler error
...................

Thanks again for your help.
Arturo

P.S. I wasn't very clear in my first message. This is not my code, as
I don't know C++. It is a code from someone else that compiled fine on
Solaris (g++ 2.95) but didn't on Linux Mandrake 9.1 (g++ 3.3). I tried
myself to hack some changes according to the compiler error/warning
messages and to what I read on the net, i.e., I replaced 'strstream.h'
with 'sstream', 'ostrstream' with 'ostringstream', 'stdio.h' with
'cstdio', but, as you see, I was still not very successful in
compiling the program...


"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<1I*******************@newsread1.news.pas.ear thlink.net>...
"Arturo DiDonna" <ar************@yahoo.it> wrote in message
news:ba**************************@posting.google.c om...
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

Jul 22 '05 #10
Arturo DiDonna wrote:
Many thanks to all of you who answered my question. I tried first Mike
Wahler suggestion and it worked like charm! Thanks again, Mike.


Note, that even though Mike's suggestion will help that piece of code to
_compile_, it still won't make it _work_. As many people already pointed
out, the code looks like an incomplete attempt to switch from using
'strstream's to using 'stringstream's. The truth is that in your case it
is not enough to just replace all 'strstream' declarations with
'stringstream' declarations and subdue any compilation errors. In its
current state the code will return a pointer to deallocated memory,
which is a serious error.

The original 'strstream'-based version would've worked. The current
'stringstream'-based one will not work because these stream classes use
very different approaches to internal memory management.

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #11

"Dylan Nicholson" <wi******@hotmail.com> wrote in message
news:7d**************************@posting.google.c om...
"Mike Wahler" <mk******@mkwahler.net> wrote in message

news:<1I*******************@newsread1.news.pas.ear thlink.net>...
buffer << '\0';
(*ch_ptr) = buffer.str(); // This is the line giving compilation
problems


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

How can that possibly produce a useful result?


I didn't say it does. I did not look at the 'logic' (or
lack of) of the code. I simply addressed the specific
error message about the 'type conflict'.

-Mike
Jul 22 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Andres Rosado-Sepulveda | last post by:
Hello, I'm having trouble compiling PHP 4.3.4 on Solaris 8. This is the error message it is showing: -- start -- Undefined first referenced symbol ...
0
by: David W. Fenton | last post by:
Today I was working on a hideous old app that I created a long time ago that does a lot of showing/hiding/resizing of fields on one of the forms. I had used constants to store reference values for...
4
by: -Michelle- | last post by:
Hi I am using A2003 on XP. The client has A2000. So I have ensured that I have developed based on A2000 and compiled as such. I have found that in a number of cases now, I have used (what I...
3
by: Dmitri Shvetsov | last post by:
Hi All, Did somebody have a problem compiling some solution in VS2003? I get the error every time that some files are locked and are using by another process. I repeat compiling again and again...
2
by: Erik | last post by:
Hi Everyone, I'm having real problems compiling some source for eVC4++. The errors I am getting are below: It all seems to be centred around winsock. If I move the afsock.h reference to before...
3
by: Ryan Riehle | last post by:
Hi All! Trying to upgrade to Apache 2.0.49 and getting compile errors related to mod_auth_pgsql, any clue?: make: Entering directory `/usr/src/httpd-2.0.49'...
2
by: nospam | last post by:
Hi Newbie asp questions: I have problems running new website when its uploaded. It compiles nicely when running on my local machine, but when compiling on the server i get the error:
0
by: phoolimin | last post by:
Dear all, I am trying to embed python into another scripting language, to do this I need to solve a number of problems on importing or compiling python script. First let me state what exactly I...
8
by: WebSnozz | last post by:
I have an application written in C that does a lot of low level stuff. It does a lot of things like casting from void*'s. I want to create a new GUI for it in either C# or MC++, but reuse the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.