Transcript ppt
Getting Started with C++
Part 2
1
Getting Started on Linux
Today we will look at Linux.
See how to copy files between
Windows and Linux
Compile and run the “Hello, World”
program.
Try out a very simple editor.
2
hello.cpp
If you don’t have hello.cpp from last
class you can download it from the class
web site:
http://www.cse.usf.edu/~turnerr/Object_Oriented_Design/Downloads/
3
Downloads Area
Download the file without the .txt extension.
Save it as hello.cpp
4
Downloading with Internet Explorer
Right click on the file name.
Select “Save Target As …”
5
Save to the Desktop
Be sure to select “All Files”
6
About Circe
All USF students have access to a Linux
system known as Circe.
Try logging in with your USF NetID.
If unsuccessful, you can set up an
account on line.
(Details follow.)
7
Connecting to Circe
Use an SSH terminal client program to
connect to Circe.
Recommended client program is PuTTY
Can download from
http://it.usf.edu/standards/security/tools
You will also need an SSH file transfer
program.
WinSCP
8
USF IT Software Page
9
Connecting with PuTTY
10
Using Circe
11
Create a Test Directory
12
Copying a File to Circe
Use an SSH file transfer program to copy
the C++ source file to an empty
directory on Circe.
WinSCP
FSecure Shell
Create a new directory if necessary.
13
Connecting to Circe with WinSCP
14
Connected to Circe
15
Pick a Directory
Pick an empty directory to work in.
Or create a new one.
16
Copy Source File
Drag source file
into remote
directory window
17
Open a Terminal Window
18
Connect to Circe and cd to Test Directory.
19
Compile the Program
20
Run It
21
Creating a Source File on Circe
Delete existing files. We will start from scratch.
22
Creating a Source File on Circe
23
Creating a Source File on Circe
Press Ctrl-o to write out the file.
24
Creating a Source File on Circe
25
Creating a Source File on Circe
Press Ctrl-x to exit.
26
Exit from the Editor
27
View the Source File
28
Compile and Run
29
The Manipulator endl
#include <iostream>
int main( void )
{
std::cout << "Hello, World!";
std::cout << std::endl;
return 0;
}
std::endl is not a character like '\n'
It is an instruction to cout to start a new line.
Referred to as a manipulator.
30
Multiple outputs with cout
#include <iostream>
int main( void )
{
std::cout << "Hello, World!" << std::endl;
std::cin.get();
return 0;
}
<< operators can be cascaded as many times as you wish.
31
Input from the Keyboard
#include <iostream>
int main( void )
{
int a;
int b;
std::cout << "Enter two integers to compute their sum:" << std::endl;
std::cin >> a;
std::cin >> b;
std::cout << "The sum of " << a << " and " << b
std::cout << a + b << std::endl;
<< " is ";
return 0;
}
32
Input from the Keyboard
33
Avoiding all those "std::"s
#include <iostream>
using namespace std;
int main( void )
{
int a;
int b;
cout << "Enter two integers to computer their sum:" << endl;
cin >> a;
cin >> b;
cout << "The sum of " << a << " and " << b
cout << a + b << endl;
<< " is ";
return 0;
}
34
Being More Selective
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
This is generally considered better practice.
int main( void )
{
int a;
int b;
cout << "Enter two integers to computer their sum:" << endl;
cin >> a;
cin >> b;
cout << "The sum of " << a << " and " << b
cout << a + b << endl;
...
return 0;
}
<< " is ";
35
Assignment
Before next class
Be sure you can connect to Circe and log
in using your USF NetID.
Do today’s examples for yourself
if you didn’t do them in class.
Read Chapters 1 and 2.
End of Presentation
36