Hola a todos, no soy programador de C++ pero estoy haciendo un proyecto y necesito q sea liviano y rapido y por ello necesito q este hecho en C++
Necesito remplazar los 3 espacios iniciales de un string.... en ocntre un codigo que es el siguiente y que funciona para remplazar strings:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str("one three two four");
string str2("three");
str.replace(str.find(str2),str2.length(),"five");
cout << str << endl;
return 0;
}
Pero cuando lo utilizo en mi proyecto me da error:
#include <iostream>
#include <stdlib.h>
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream in("archivo.txt"); // Open for reading
ofstream out("j.txt"); // Open for writing
string s;
string re(" ");
while(getline(in, s)) // Discards newline char
s.replace(s.find(re),re.length(),"");
out << s << "\n"; // ... must add it back
system("pause>nul");
}
(El programa copia un archivo llamado "archivo.txt" a otro llamado "j.txt" y tiene que quitar los 3 espacios q van a haber al inicio del string)....... pero da error......
Porque sucede esto????