-
Using replace()
this code won't compile:
Code:
char word[256];
ifstream in("test_data.txt");
in.getline(word, 256);
replace(word.begin(),word.end(), ',' , ' ');
in.close();
what it tries to do is to replace all the commas in word with spaces...if i define word as a string it works...but then getline doesn't work...
Thanks!
Farooq
-
begin and end are member functions for STL container objects, a simple character array is not one of those. If you want to use a character array and the replace function you will need to do it this way:
Code:
char word[256];
ifstream in("test_data.txt");
in.getline(word, 256);
replace(word,word+256, ',' , ' ');
in.close();
-
>>if i define word as a string it works...but then getline doesn't work...
You just have to use the template version of getline:
Code:
std::string word;
std::ifstream in("test_data.txt");
std::getline(in, word);
-
thanks guys...ill work on this...