Answer the question
In order to leave comments, you need to log in
How to add a char array of 2 or more words to a structure?
Actually, the problem with adding to the structure ... If I add one word to Enter the manufacturer, for example Ford, then everything will be displayed without problems.
But if I enter Lamborgini Diablo, then after pressing Enter, the program ends.
Tried cin.getline(kolcar->namecar), getline(cin,kolcar->namecar) but the error didn't go away
#include "stdafx.h"
#include <iostream>
#include <string>
#include <conio.h>
struct car
{
char namecar[80];
int godvipuska;
};
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
int kolvoavt = 0;
string str1;
cout << "Сколько автомобилей поместить в каталог ?: ";
cin >> kolvoavt;
car *kolcar = new car[kolvoavt];
for (int it = 0; it < kolvoavt; it++)
{
cout << "Автомобиль #" << it + 1 << endl;
cout << "Введите производителя: "<<endl;
cin>>kolcar->namecar;
cout << "Укажите год выпуска: "<<endl;
cin >> (*kolcar).godvipuska;
kolcar++;
}
cout << "Вот ваша коллекция :" << endl;
for (int it = 0; it < kolvoavt; it++)
{
kolcar--;
cout << kolcar->godvipuska <<" "<< kolcar->namecar<<endl;
}
delete kolcar;
system("pause");
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question