Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/11/2011, 03:00
kyc212
 
Fecha de Ingreso: octubre-2009
Mensajes: 21
Antigüedad: 14 años, 11 meses
Puntos: 0
Exclamación Conversiones de tipo datos

Hola soy nueva en C++ y necesito ayuda con lo mas basico ya que lo intentado hacer que me funcione sin tener mayor exito.

Tengo un fichero que contiene los sgtes datos :

Person One
56.09

Second Person
98.44

ahora mi programa tiene que leer estos datos y escribirlos en otro fichero pero cuando lea el numero decimal tiene que multiplicar por 1.10 lo cual no sucede ya que considera que no es digito. La verdad no se como convertir de cadena a entero.

#include <iostream>
#include<string>
#include<fstream>
#include<cctype>
#include <stdio.h>
#include <stdlib.h>
using namespace std;


int main( )
{
char name2[100];
ofstream fout;
cout<<"Enter Name of output file: "<<endl;
cin.getline(name2,100);
fout.open(name2);
if(fout.fail()){
cout<<"Unabled to open the file to write";
exit(1);
}

char name[100];
cout<< "Enter Name of input file: "<<endl;
cin.getline(name, 100);
ifstream fin;
fin.open(name);

if(fin.fail()){
cout<<"Unabled to read the file";
exit(1);
}else{
string type;

while(getline(fin,type)){
int x=atoi(type.c_str());
if(isdigit(x)){
x=x*1.10;
cout<<x<<" numero ***"<<endl;
fout<<x<<" "<<endl;
}else if( type!=" " ){

cout<<type<<" "<<endl;
fout<<type<<" "<<endl;

}
//fin.ignore(10000, '\n');
}
}
fin.close();
fout.close();
system("pause");

}
Espero y me puedan ayudar a solucionar este problema gracias!!