Ver Mensaje Individual
  #3 (permalink)  
Antiguo 21/12/2013, 12:25
baterista41
 
Fecha de Ingreso: junio-2012
Mensajes: 32
Antigüedad: 11 años, 10 meses
Puntos: 1
Respuesta: Sumar Numeros de un fichero

Muy cierto seria mas entendible,haber aqui esta

Código C++:
Ver original
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. void separando(char*);
  9.  
  10.  
  11. void separando(char *cadena){
  12.  
  13. char *contenedor;
  14. string convertirString;
  15. int suma=0;
  16.  
  17.  
  18. contenedor=strtok(cadena," , ");
  19. while(contenedor!=NULL){
  20.  
  21. convertirString+=string(contenedor);
  22. // suma+=atoi(convertirString.c_str());
  23.  
  24.  
  25. contenedor=strtok(NULL," , ");
  26.  
  27.  
  28. }
  29.  
  30. //cout<<suma<<endl;
  31. cout<<convertirString<<endl;
  32.  
  33.  
  34. }
  35.  
  36.  
  37.  
  38.  
  39. int main(){
  40.  
  41. ifstream archivo;
  42. char cadena[80];
  43.  
  44.  
  45. archivo.open("SumaDificil.txt",ios::in);
  46.  
  47. if(archivo.fail())
  48. cout<<"Error al abrir el archivo"<<endl;
  49.  
  50. else{
  51. while(!archivo.eof()){
  52. archivo.getline(cadena,sizeof(cadena));
  53.  
  54. separando(cadena);
  55.  
  56.  
  57. }
  58.  
  59.  
  60.  
  61. archivo.close();
  62.  
  63. }
  64.  
  65.  
  66.  
  67.  
  68.  
  69. cin.get();
  70.  
  71.  
  72.  
  73. return 0;
  74. }