Skip to content

Instantly share code, notes, and snippets.

@calebreister
Created March 9, 2014 07:21
Show Gist options
  • Save calebreister/9444047 to your computer and use it in GitHub Desktop.
Save calebreister/9444047 to your computer and use it in GitHub Desktop.
Simple example of a use of argc and argv.
#include <iostream>
#include <fstream>
using namespace std;
const int WIDTH = 2000;
const int HEIGHT = 300;
const int COLOR = 3; //0=red, 1=green, 2=blue
//void main(int argc, char** args[])
int main(int argc, char* argv[])
{
// static unsigned char image[WIDTH][HEIGHT][COLOR];
// cout << sizeof(image);
cout << "argc: " << argc << endl;
for (int x = 0; x < argc; x++)
cout << "argv[" << x << "]: " << argv[x] << endl;
if (argc <= 1)
return 1;
//open file and print to console charater by charater
ifstream in;
in.open(argv[1]);
if (!in)
{
cout << "Error: File could not be opened!";
cin.get();
return 2;
}
char data;
// while (in >> data)
while (!in.eof())
{
in.get(data);
cout << data;
}
in.close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment