What is "String Concatenation" exactly?

Oct 9, 2018 at 11:45pm
I have been instructed not to use string concatenation in a project but this terminology hasn't been defined yet in the book or in class.

Looking online every example seemed really complicated and didn't make sense.

If someone could explain or show me this in the simplest way they could it be appreciated.

Following this is my code that I don't know if it falls into this catagory.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;

void showStars(int numStars);


int main()
{
    int N;
   cout << "How many stars would you like to show?: ";
   cin >> N;

   showStars(N);
    return 0;
}

void showStars(int numStars)
{
    for (int row = 0; row < numStars; row++)
    {
        cout << "*";
        for (int totstars = 0; totstars < row; totstars++)
        {
            cout << "*";
        }
        cout << endl;
    }
}
Oct 9, 2018 at 11:57pm
To "concatenate" (or just "catenate") is to append, or connect together.
https://www.google.com/search?q=define%3A+concatenate

For example, the strings "foo" and "bar" can be concatenated to yield the string "foobar".
In C, we'd do this with the standard C library function strcat(), which you are not using, or if we had objects that had type std::string, we'd concatenate them with the plus sign, like this:

1
2
3
4
5
6
7
8
9
10
11
#include <string>
using namespace std;

int main()
{
  string a = "foo";
  string b = "bar"; 

  // concatenate a and b to yield "foobar", store the result in c.
  string c = a + b;
}
Last edited on Oct 9, 2018 at 11:59pm
Oct 10, 2018 at 12:29am
so based on that definition it looks like my program falls outside of those parameters correct?
Oct 10, 2018 at 12:31am
Yes
Topic archived. No new replies allowed.