copiar de manera inversa entre archivos



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  int main(int argc,char **argv){
     
	vector<string> skynya;
	vector<string>::reverse_iterator it;
	string text;
    
	if(argc!=3){
		cout<<"error en los argumentos\n";
	}
	else{
		ifstream in(argv[1]);
                ofstream out(argv[2]);
        
		while(!in.eof()){
			getline(in,text);
			skynya.push_back(text);
		}
		for(it=skynya.rbegin();it != skynya.rend();it++){
			out<<*it<<endl;
		}
		cout<<"\n\n\t\ttrabajo terminado\n\n\n";
	}
	
}
Title translated: Conversely copy between files

Hola, se puede utilizar Google traducir? Lo utilicé para escribir este mensaje: No hablo español: +) La mayoría de las personas utilizan aquí Inglés.

¿Cuál es tu pregunta?

Una cosa a evitar: No bucle en el final del archivo, el bucle sólo en el nombre de la secuencia de archivo.

1
2
3
while(in) {

}


https://translate.google.com

Hello, can you use Google translate? I used it to write this message: I don't speak Spanish :+) Most people here use English.

What is your question?

One thing to avoid: Don't loop on end of file, just loop on the name of the file stream.

Su código con archivos de inclusión y espacio de nombres estándar.
Your code with include files and standard namespace.

Compila ahora
It compiles now

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
  #include <vector>
  #include <string>
  #include <fstream>
  
  int main(int argc,char **argv){
     
	std::vector<std::string> skynya;
	std::vector<std::string>::reverse_iterator it;
	std::string text;
    
	if(argc!=3){
		std::cout<<"error en los argumentos\n";
	}
	else{
		std::ifstream in(argv[1]);
                std::ofstream out(argv[2]);
        
		while(in){
			getline(in,text);
			skynya.push_back(text);
		}
		for(it=skynya.rbegin();it != skynya.rend();it++){
			out<<*it<<std::endl;
		}
		std::cout<<"\n\n\t\ttrabajo terminado\n\n\n";
	}
	
}
closed account (48T7M4Gy)
In that case TIM shouldn't it be #include<cuerda> ?
In that case TIM shouldn't it be #include<cuerda> ?


Ha ha, I don't know. Whatever squeals one's wheels :+) I am sure the OP knows what language the header files use for their names. If I had to guess, I would have thought that header file names are in English; variables, functions and comments can be in whatever language one likes. But there is always potential for me to be burnt by "I knew that I thought, and I thought that I knew" type statements :+D
> Conversely copy between files
Reverse copy.

> Don't loop on end of file, just loop on the name of the file stream.
Loop on the reading operation. while( getline(in,text) )

The problem with the .eof() (and TheIdeasMan's solution) is that the last reading was not good, but you operate on the string regardless.


Utiliza como condición la operación de lectura.
El problema con .eof() (y con la solución de TheIdeasMan) es que la última lectura falla, pero de todas formas operas en esa cadena de caracteres.


> can you use Google translate?
If the destination language is unknown, you ought to include the original text too.
Si no conoces el idioma de destino, incluye además el texto original.
@ne555

Thanks :+)

> Conversely copy


A danger in using Google Translate, I suppose.

Reverse copy.


yes, the OP's code had reverse iterators

Regards :+)
Topic archived. No new replies allowed.