-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum.cpp
More file actions
23 lines (18 loc) · 866 Bytes
/
sum.cpp
File metadata and controls
23 lines (18 loc) · 866 Bytes
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> // Required for input/output operations (std::cout)
#include <cstdlib> // Required for atoi (converts string to integer)
int main(int argc, char *argv[]) {
// argc is the argument count, including the program name itself.
// argv is an array of strings (char pointers), where each element
// is a command-line argument.
// Check if exactly one argument (besides the program name) is provided.
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <integer>" << std::endl;
return 1; // Indicate an error
}
// Convert the first command-line argument (argv[1]) to an integer.
// argv[0] is the program's name.
int num = std::atoi(argv[1]);
// Print the received integer.
std::cout << "The integer received is: " << num << std::endl;
return 0; // Indicate successful execution
}