Question about the declaration of strings as data types in functions

0

main.cpp

#include <iostream>
#include <fstream>
#include <cstdlib>
#include "Cliente.h"

using namespace std;

int main()
{
ofstream creditoSalida("credito.dat", ios:: binary);

if(!creditoSalida){
    cerr << " No se pudo abrir el archivo. " << endl;
    exit(1);
}

Cliente clienteEnBlanco;

for(int i = 0; i < 100; i++)

    creditoSalida.write(reinterpret_cast<const char *> (&clienteEnBlanco), sizeof(Cliente));
return 0;
}

clients.h

#ifndef CLIENTE_H
#define CLIENTE_H

class Cliente
{
  private:

  int numeroCuenta;

  char apellido[15];

  char primerNombre[10];

  string prueba = "";

  double saldo;

  public:
     Cliente(int = 0, string = "", string = "", double = 0.0);

    void establecerNumeroCuenta(int);
    int obtenerNumeroCuenta();
    void establecerApellido(string);
    string obtenerApellido();
    void establecerPrimerNombre(string);
    string obtenerPrimerNombre();
    void establecerSaldo(double);
    double obtenerSaldo();
};

#endif // CLIENTE_H

cliente.cpp

#include "Cliente.h"

Cliente::Cliente(int valorNumeroCuenta, string valorApellido, string   valorPrimerNombre, double valorSaldo)
{
   establecerNumeroCuenta(valorNumeroCuenta);
establecerApellido(valorApellido);
establecerPrimerNombre(valorPrimerNombre);
establecerSaldo(valorSaldo);
}

void Cliente::establecerNumeroCuenta(int valorNumeroCuenta)
{
     numeroCuenta = valorNumeroCuenta;
}

int Cliente::obtenerNumeroCuenta()
{
    return numeroCuenta;
}

void Cliente::establecerApellido(string valorApellido)
{
     apellido = valorApellido;
}

string Cliente::obtenerApellido()
{
    return apellido;
}

void Cliente::establecerPrimerNombre(string valorPrimerNombre)
{

    primerNombre = valorPrimerNombre;
}

string Cliente::obtenerPrimerNombre()
{
   return primerNombre;
}

void Cliente::establecerSaldo(double valorSaldo)
{
   saldo = valorSaldo;
}

double Cliente::obtenerSaldo()
{
  return saldo;
}

When compiling I get an error that says: "Error: string does not name a type" This error points to one of the prototype functions that I have as "string getLastName ();" Why ? it seems that it does not recognize string as a data type for a function prototype, but the other types of data accept them as functions

    
asked by Marco Leslie 30.08.2017 в 23:53
source

1 answer

1

Rapid response (development tomorrow):

You have not included the string library, with the line:

#include <string>

This library is part of the standard c ++ libraries: link

The other types of data (void, int, char, etc.) are basic types of the system, so you do not need to define them or include any library that defines them.

    
answered by 31.08.2017 в 00:08