views

Open Visual Studios and start a new project. To start a new project, click on the New Project link on the left side of the screen. A new window will appear. Select visual C++ from the left side of the screen, and select Empty Project from the middle section of the screen. At the bottom of the window you can give the project a name, and then click OK to create the new project.

Right click Source File on the right hand side of the screen, Click Add, then click Add New Item. This will open a new window.

Select the C++.cpp file option from the middle section of the screen. Then click Add to add the CPP file in which you will write your code.

Add three lines of code to the top of the project. Add #include

Set up the main function of the program. Type the lines of code in the above picture. Main is the function that runs first in a C++. When 0 is returned at the end of the function, the program knows to end.

Write string in the same place as the screenshot above. For this project we will be asking the user to enter their name. The data type used to hold multiple characters are called strings.

Choose a variable name to hold the inputted data. Names are usually related to the type of data they are holding. In this example, you will be asking for a name, so name the variable name.

Initialize the variable to a default value. For string, set them to an empty string by assigning them the value "".

Output a statement to the user to get the input you desire. Output statements are written as: cout << “Enter your name : ”

Get the input from the user. You can store what they have typed in to the variable with a cin statement. Example: cin >> name; This will store what the user enters into the string variable you created.

Output a statement and use the input you received in step 8. cout << “Your name is “ << name;

Click the run button on the program and test it out. The run button is the button that has the play symbol on it and is called Local Windows Debugger. Once you click that button, your program will run asking for your name and then outputting your name back to you. If you made an errors, the compiler will list the error messages. Make sure no lines of code are underlined in red. If they are, check to make sure you did not forget a step or made a typo. If your program runs correctly, then congratulations, you have just performed input and output operations in C++.
Comments
0 comment