Reputation: 1
I am new to c++ programming I have an assignment the takes the content of a txt file and checks the content with a dictionary txt file. When I send the string[] to my function I always get an error which states that the std::basic string can not be converted to std::strin
ifstream d_file("dictionary.txt");
string l;
vector<string> user_vec;
while( getline( d_file, l ) ) {
user_vec.push_back( l);
}
size_t line_count = user_vec.size();
for( size_t i = 0; i < line_count; ++i )
{
// cout << i << " " << user_vec[i] << endl;
bool result = inDictionary(word, user_vec[i]);
}
}
bool inDictionary(string word,string dictionary[])
{
cout<<word<< dictionary<<endl;
}
Upvotes: 0
Views: 78
Reputation: 13532
You are passing in a string the function is expecting a string array.
Change inDictionary
to the following since user_vec[i]
is a string.
bool inDictionary(string& word,string& dictionary)
{
cout<<word<< dictionary<<endl;
}
Or if you want to pass in all the lines into the inDictionary
function pass the vector into the function.
bool inDictionary(string& word, std::vector<string>& dictionary)
{
//...
}
Then you would pass the vector like bool result = inDictionary(word, user_vec);
.
Hope that helps.
Upvotes: 1
Reputation: 23634
user_vec[i]
is a string;
string dictionary[]
is string array, type mismatch.
You have to change the prototype of the inDictionary
function.
Upvotes: 0