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