私はこの新しいコードを持っていますが、データを印刷しようとすると文字列変数が決して印刷されません。 これはちょうど のためのものです。私は実践的なリアーソンのために "goto"を使用しています。文字列は印刷されません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;
}
編集 ここgoto
の使用はint型メイン
あなたの 'main'関数は何ですか? –
クラスを使用する場所で 'main()'を追加できますか? –
完了、ありがとうございます。 – 005197503