Wednesday, September 21, 2016

Getting good at: C++ | #5 - Strings

Stuff you don't care about

This blog has breached 100 views already. If it got that many views in the time it existed, you better believe I'm gonna shamelessly promote my channel.

5 - Bad Password Program

So today, we're going to be writing a program that takes advantage of strings. In case you don't know what a string is, it's basically an object, and with all objects comes classes. This particular object comes from the class <string>. How you would implement this class is by typing #include <string>. In fact, that's how you implement most classes, but more on that later. For now, let's write a terrible password program. To start, create your string, and set it to what you want. For example:

{
     string harambe;



}

Then use cin >> to allow the user to input the string, so in this case, 'harambe':

{
     string harambe;
     cin >> harambe;


}

Then, let's output some text; in this case, "personal information":

{
     string harambe;
     cin >> harambe;
     cout << "sub to control alt defeat" << endl;
     return 0;
}

After you compile it, you should see something like this:

Note that the top (harambe) is our input, and the bottom (f) is our output. Keep in mind this is a terrible password program, because you can type whatever you want and you'll get the exact same result, as shown here:



In case you're wondering, I used \n to space the input and output so it would be easier to explain.

I'll show you how to change that in the next post. Until then...






No comments:

Post a Comment