Ver Mensaje Individual
  #2 (permalink)  
Antiguo 04/10/2010, 18:11
fightmx
 
Fecha de Ingreso: febrero-2003
Ubicación: D.F.
Mensajes: 163
Antigüedad: 21 años, 3 meses
Puntos: 22
Respuesta: Runtime Error SIGSEGV

Me parece que no tomas en cuenta que la cadena a buscar puede aparecer una o varias veces en la misma línea (reemp), además podrías evitar el uso del vector.

Ejemplo:
Código C++:
Ver original
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. void replaceAll(string &s, const string &what, const string &with){
  6.     string::size_type start = 0;
  7.     string::size_type whatsz = what.size();
  8.     string::size_type withsz = with.size();
  9.  
  10.     while(start = s.find(what, start), start != string::npos){
  11.         s.replace(start, whatsz, with);
  12.         start += withsz;
  13.     }
  14. }
  15.  
  16. int main(){
  17.  
  18.     string what, with;
  19.  
  20.     getline(cin, what);
  21.     getline(cin, with);
  22.  
  23.     string line;
  24.     while(getline(cin, line)){
  25.         replaceAll(line, what, with);
  26.         cout << line << endl;
  27.     }
  28.  
  29.     return 0;
  30. }

Saludos.