Ich bin sehr neu in der Programmierung, ich habe diesen großen Code, aber wenn ich versuche, die Daten zu drucken druckt die String-Variable, können Sie helfen? dies ist nur für ich benutze "goto" nur für praktische reassons.Zeichenkette no print C++
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class producto
{
public:
int id;
string nombre;
string descripcion;
int precio;
void registrar();
void ver();
};
void producto::registrar()
{
cout << "Codigo:" << endl;
cin >> id;
cin.ignore();
cout << "Nombre del producto:" << endl;
getline(cin, nombre);
cout << "Descripcion del producto:" << endl;
getline(cin, descripcion);
cout << "Precio:" << endl;
cin >> precio;
}
void producto::ver()
{
cout << "ID del producto:";
cout << id << endl;
cout << "Nombre del producto:" << endl;
cout << nombre;
cout << "Descripcion del producto:";
cout << descripcion<<endl;
cout << "Precio:";
cout << "$" << precio << endl;
}
int main()
{
menu1:
int menu;
producto cosa;
cout << "************************" << endl;
cout << "1.- Registrar Producto" << endl;
cout << "2.- Ver Producto" << endl;
cout << "************************" << endl;
cin >> menu;
cin.ignore();
switch (menu)
{
case 1:
cout << "INGRESE PRODUCTO NUEVO:\nPresione enter para continuar" << endl;
cin.ignore();
system("cls");
cosa.registrar();
cin.ignore();
break;
case 2:
cosa.ver();
cout << "Presione enter para regresar al menu principal." << endl;
cin.ignore();
break;
}
goto menu1;
return 0;
}
bearbeiten Hier ist der int main
Was ist Ihre 'Hauptfunktion'? –
Könnten Sie ein 'main()' hinzufügen, in dem Sie Ihre Klasse verwenden? –
Fertig, danke. – 005197503