Correctly solved homework?

In General a trivial task and in fact very easy, but I have no experience with c++, all the same, pitfalls in it much... Just started to learn it. Please tell me whether the solution described.
You need to write a program that asks for name, surname, and then constructs, stores and displays the string in the form "Surname, Name". It was necessary to use char and functions from cstring.

Kind of like running, but you never know. Maybe we should do something differently? And how can you get rid of the static size of arrays?
#include <iostream>

using namespace std;

const int Buffer_size = 100;

int main()
{
 char first_name[Buffer_size];
 char last_name[Buffer_size];
 char full_name[Buffer_size * 2];

 cout << "Enter your first name: ";

 cin >> first_name;

 cout << "Enter your last_name: ";

 cin >> last_name;

 strcpy_s(full_name, Buffer_size + 1, last_name);
 strcat_s(full_name, ", ");
 strcat_s(full_name, first_name);

 cout << "Here's the information in a single string:" << full_name << endl;

system("pause");

 return 0;
}</iostream>
June 14th 19 at 18:05
2 answers
June 14th 19 at 18:07
It's some kind of C-with-classes. Use std::string for strings.
It was necessary to use char and functions from cstring.
- charity84 commented on June 14th 19 at 18:10
Well , the author stands to throw the textbook or teacher for a window. - orin.Runte commented on June 14th 19 at 18:13
obviously this is a learning exercise (where the bike is a great way to understand the complex device, and not to use ready-made "magic") and not production code. If you open the source code of std::string, then there will be the infamous char's. Adjusted for the template, of course.

Such comments would be worth to write in comments to the question. - Elna.Volkman92 commented on June 14th 19 at 18:16
it's not a great way to find out, it already uses features... a Great way was on the operating systems and microprocessors with Assembly language at the University XA But it's not entry level, even while doing so
string firstName, string lastName... stringToPrint = firstName+lastName
and when you get the basics, going on to ask questions, like why is this so? because IMHO the self-taught it's a wild loss of time and perhaps even motivation with the desire :D - thalia.Hermann50 commented on June 14th 19 at 18:19
functions And not dizzying template classes. The point "IMHO". There are two teaching methods: bottom-up and top-down. The second approach will give a false sense of ownership of the subject.
At uni or not at uni - this is the kind of metaphysics. What's the difference where to do it, if the person ocilator? - Elna.Volkman92 commented on June 14th 19 at 18:22
duck and what he is told to do now the book is not about turns?) - thalia.Hermann50 commented on June 14th 19 at 18:25
, человек набивает шишки в работе с сырой памятью, учится пользоваться нуль-терминированными строками. Это базовые вещи, которые останутся тайной при работе с std::string и подобными классами. - Elna.Volkman92 commented on June 14th 19 at 18:28
it's only the sample jobs. Following this mission it was the same thing but using a string. Besides the topic was about arrays and pointers, string still inside is an array of characters. - Jace43 commented on June 14th 19 at 18:31
the book of Stephen Prata. The C++ programming language. The lectures and exercises. what is she to you?
These tasks are in any book. - Jace43 commented on June 14th 19 at 18:34
June 14th 19 at 18:09
  1. If the user enters first name or last name longer than 100 characters will be a buffer overflow, it is necessary to limit the maximum number of characters to read. Cm.
    iomanip.
  2. In the call to strcpy_s don't need to add to the size of the buffer unit, in this case this is not a bug.
  3. strcpy_s and strcat_s new in C++17, again, not a bug, but a reason to meditate.
if you do not specify at least one more fails.
and at the expense of c++17, I have not yet distinguished the new from the old. In the book at all the examples use the strcpy, strcat, but I have a Studio throws a warning that these functions are not safe and need to use strcpy_s/strcat_s. Although the book still mentions the function strncpy. And what could be the problem of using functions from the new standard? Why should think? - charity84 commented on June 14th 19 at 18:12
,
> And what can be the problem of using functions from the new standard? Why should think?
First, the standard-that's not out yet.
Secondly, where do these functions come from and what is the likelihood that other compilers support them? Specifically, the couple — originally a Microsoft extension.

> Studio throws a warning that these functions are not safe and need to use strcpy_s/strcat_s.
Right throws: in the initial versions way too easy to get a buffer overflow. - orin.Runte commented on June 14th 19 at 18:15
unfortunately now is not present under the arm compiler supports the C11 Annex K and, therefore, can't check. By the way, you forgot to count the place for a comma and a space behind it, may still be overflow. - Elna.Volkman92 commented on June 14th 19 at 18:18
learn to program in C++, not Microsoft(R) Visual(TM) C++. Ignore this particular warning and quietly write strcpy/strcat. Generally, of course, in practice it is better to use std::string, but it you'll get. - thalia.Hermann50 commented on June 14th 19 at 18:21
, in principle, the string class has already passed, all in the same theme. With string the solution is generally trivial, exactly the same as in any object oriented language. first_name + ", " + last_name - Elna.Volkman92 commented on June 14th 19 at 18:24

Find more questions by tags C++