Strings

So I've been following TheNewBoston's tutorials and I think I've made good progress. But this tutorial his guide just left me in the dark. He introduced a new term he hadn't used before, string. What is this? The code he uses is below but I have no idea what it means or what he is doing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 #include <iostream>
#include <string>

using namespace std;
int main();

class Cool{
    public:
        void setName(string x){
            name = x;
        }
        string getName(){
            return name;
        }
    private:
        string name;
};

int main() {


    return 0;
}
String is a string: sequence of characters.
consider this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>

int main() 
{
    std::string name;
    std::cout << "WHat is your name?\n";
    std::cin >> name;
    std::cout << "Hello, " << name << "!\n";

    std::string HW = ", ";
    HW = "Hello" + HW;
    HW += "world!";
    std::cout << HW << '\n';
}
WHat is your name?
Mike
Hello, Mike!
Hello, world!
He is not actually using the function getName() in the code. He is just showing you how to declare it in the class.
A string is basically what you are reading right now. It is basically just a quotation of whatever amount of letters and/or numbers. It took me a while to just understand that when I started getting into programming. Just let us know if you still have trouble understanding.
> He introduced a new term he hadn't used before, string. What is this?

Reading this would help: http://www.mochima.com/tutorials/strings.html
Topic archived. No new replies allowed.