Похожие чаты

Can someone explain this error?

10 ответов

8 просмотров
Caroline- Автор вопроса

@gameraccoon when i write Getline(cin, name[i]) Instead cin name I got this error!

Caroline- Автор вопроса
Caroline
@gameraccoon when i write Getline(cin, name[i]) In...

That is strange, can you paste the code somewhere (e.g. pastebin) so I can copy and execute it?

Caroline- Автор вопроса

I found this, you probably need to do cin.ignore(), before first getline call. https://stackoverflow.com/questions/36374710/using-multiple-getline-calls-to-read-multiple-lines

By the way, I can give you some suggestions how this code can be improved (from readability and maintainability perspective), do you need it?

Caroline- Автор вопроса
Pavel
By the way, I can give you some suggestions how th...

yes i need it, i wanna know your suggestions bro, appreciate it

Caroline
yes i need it, i wanna know your suggestions bro,...

First of all, instead of using raw arrays you can use std::vector. It will allow you to do the same logic but without need to call delete manually (so you don't have a chance to forget to do it, especially if your function will have multiple returns in future). So you can just create variables of types std::vector<char> and std::vector<std::string>> and call resize(size) to make them allocate 3 items for you. Then you can use it like you already using it and the items will be deallocated in the end of the function automatically. The pattern that vector uses called RAII. Instead of having a separate array for first letter, you can do one of the following: Either do to upper on the first symbol in the cout call. E.g. cout << toupper(name[i].at(0)) << ...;. Or in your loop you can assign result of toupper back to the first symbol. Something like name[i][0] = toupper(name[i][0]);. I would prefer the second way. If you use vector instead of raw array, you can use range-based loops instead of iterating over i. So your loops will look like: for (auto& line : name){ And you will use line instead of name[i]. And a minor suggestion, it's better not to use using namespace std in real code. It is good for code examples to make them shorter, but in real code it can create issues. https://www.geeksforgeeks.org/using-namespace-std-considered-bad-practice/ Other than that, the code looks good to me. Nice use of transform 👍

Похожие вопросы

Обсуждают сегодня

Hey guys, did you see the new announcement about $Fun? 🔥
Filip Murphy
55
А чем вам питонисты не угодили?😂
.
79
Язык Си можно выучить за день? По книжке ANSI C на 230 страниц
Vincent Vegan
29
Привет, запускаю werf в dind в k8s, получаю ошибку на этапе build/beforeSetup: /.werf/stapel/embedded/bin/bash: /.werf/scripts/5898bdfe5214357d3706b879cc8d3d78460fb379607cbd...
florius0
7
пацаны, как-нибудь можно панель задач заблюрить, что она была похожа на kde или винду 7, 11?
В
16
Всем привет, написал код ниже, но он выдает сегфолт, в чем причина? #include <stdio.h> #include <stdlib.h> #include <string.h> struct product { char *name; float price; };...
buzz базз
75
Dim Dim, [02.07.2024 11:07] DB 0x62 Dim Dim, [02.07.2024 11:07] DB 0x66 Dim Dim, [02.07.2024 11:07] кто пояснит что это?
Dim Dim
14
So total 101m burned Today?
Simu
18
Ошибка: segmentation fault (core dumped) Код: pastebin.com/BEsNNSSV Сообщение от компилятора: отсутствует ОС: Arch Linux Ядро: x86_64 Linux 6.9.7-arch1-1 Процессор: Intel Cele...
sec
4
Hi, I can't understand promises in JavaScript and what we should use them for (maybe the teacher didn't teach well XD). Do you have a solution for this? And are promises used...
A
29
Карта сайта