T
theronnightstar
I seem to be having a problem with getline(). I have tried to find it
on
google, but I'm not seeing the answer. The goal of this section of
code
is simply to read in a line from a file to a string according to the
conditions of the do...while statement.
/////code
void populate( vector<string>& unplayed_anagrams, string& word, const
ifstream& dict_word_list )
{
const int max_size = word.size() + 1;
int letters_left;
char word_array[max_size];
char test_word_array[max_size];
string measure_word = " ";
vector<int> used_letters;
vector<int>::iterator iter;
used_letters.clear();
memset( test_word_array, '\0', max_size);
memset( word_array, '\0', max_size);
strcpy( word_array, word.c_str() );
cout << "Please wait... Populating the arrays." << endl;
while( !dict_word_list.eof() )
{
letters_left = (max_size - 1 ) ;
do
{
getline( dict_word_list, measure_word ); //<-This is the
offending code
}
while((measure_word.size() > word.size() && measure_word.size() <
3) || measure_word == word);
\\\\\code
I have another section of code that does almost the same thing, with
the
exception that it works.
/////code
void load_words( string& word, ifstream& dict_file )
{
vector<string> temp_vector;
int random_num = 0;
int temp_size = 0;
string line = " ";
temp_vector.clear();
while( word.size() < 6 )
{
while( !dict_file.eof() )
{
getline( dict_file, line );
temp_vector.push_back( line );
++temp_size;
}
random_num = ( rand() % temp_size );
word = temp_vector[random_num];
}
}
\\\\\code
When I compile the code, I get a compile time error pointing to the
getline() in the first chunk of code.
/////error
jaag.cc: In function 'void
populate(std::vector<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >&, std::string&, const std::ifstream&)':
jaag.cc:126: error: invalid conversion from 'void*' to 'char**'
jaag.cc:126: error: cannot convert 'std::string' to 'size_t*' for
argument '2' to '__ssize_t getline(char**, size_t*, FILE*)'
\\\\\error
I was using these includes:
/////code
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <fstream>
#include <string>
\\\\\code
as best as I can figure it I am getting the C version of getline() in
the first one and the C++ version in the second one. I can't figure
it
out. That's not what I need. I want them both to be C++. Any help on
this
would be greatly appreciated.
Thanks
PS I am using gcc-4.1.2 on amd64-gentoo-linux. If you need, I can
post
the code that is calling these functions. Thanks again.
on
google, but I'm not seeing the answer. The goal of this section of
code
is simply to read in a line from a file to a string according to the
conditions of the do...while statement.
/////code
void populate( vector<string>& unplayed_anagrams, string& word, const
ifstream& dict_word_list )
{
const int max_size = word.size() + 1;
int letters_left;
char word_array[max_size];
char test_word_array[max_size];
string measure_word = " ";
vector<int> used_letters;
vector<int>::iterator iter;
used_letters.clear();
memset( test_word_array, '\0', max_size);
memset( word_array, '\0', max_size);
strcpy( word_array, word.c_str() );
cout << "Please wait... Populating the arrays." << endl;
while( !dict_word_list.eof() )
{
letters_left = (max_size - 1 ) ;
do
{
getline( dict_word_list, measure_word ); //<-This is the
offending code
}
while((measure_word.size() > word.size() && measure_word.size() <
3) || measure_word == word);
\\\\\code
I have another section of code that does almost the same thing, with
the
exception that it works.
/////code
void load_words( string& word, ifstream& dict_file )
{
vector<string> temp_vector;
int random_num = 0;
int temp_size = 0;
string line = " ";
temp_vector.clear();
while( word.size() < 6 )
{
while( !dict_file.eof() )
{
getline( dict_file, line );
temp_vector.push_back( line );
++temp_size;
}
random_num = ( rand() % temp_size );
word = temp_vector[random_num];
}
}
\\\\\code
When I compile the code, I get a compile time error pointing to the
getline() in the first chunk of code.
/////error
jaag.cc: In function 'void
populate(std::vector<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >&, std::string&, const std::ifstream&)':
jaag.cc:126: error: invalid conversion from 'void*' to 'char**'
jaag.cc:126: error: cannot convert 'std::string' to 'size_t*' for
argument '2' to '__ssize_t getline(char**, size_t*, FILE*)'
\\\\\error
I was using these includes:
/////code
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <fstream>
#include <string>
\\\\\code
as best as I can figure it I am getting the C version of getline() in
the first one and the C++ version in the second one. I can't figure
it
out. That's not what I need. I want them both to be C++. Any help on
this
would be greatly appreciated.
Thanks
PS I am using gcc-4.1.2 on amd64-gentoo-linux. If you need, I can
post
the code that is calling these functions. Thanks again.