All pastes #104178 Raw Edit

Anonymous

public text v1 · immutable
#104178 ·published 2006-07-28 18:07 UTC
rendered paste body
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int readfile(void);
int printNames(void);


int main(int argc, char *argv[])
{

int choice = 0;
bool numExit = false;

while (numExit != true)
{
	cout << "1. Read File" << endl << "2. Hello World!" << endl <<"3. Print Commandline Argument "<< endl << "4. End Program" <<endl;
	cin>>choice;

	switch (choice)
	{
	case 1:
		readfile();
		break;
	case 2:
		cout<< "Hello World! "<<endl;
		break;	
	case 3:
	
		if (argc < 2)
		{
			cout<< "Error not enough arguments" <<endl;
		}
		else
		{
			for (int i = 1; i < argc; i++)
			{
				cout<< "Hello " << argv[i] << "!" <<endl;
			}
			
		}
		break;
	case 4:
		numExit = true;
		break;
	default:
		break;
	}				
} 

}

int readfile(void)
{
		ifstream fin;
		string name = "";
		fin.open ("helloworld.txt");


		if (fin.fail())
		{
			cout<<"Error could not open file!" <<endl;
		}

		getline(fin, name);

		if (name == "")
		{
			cout<< "Hello World!"<<endl;
		}

		else 
		{
			//Make sure the first line is read first (there is probably a better way to do this)

			cout << "Hello " <<name << "!" <<endl;
			while(fin >> name)
			{
				cout<< "Hello " << name << "!" << endl;
			}
		}

		fin.close();
		return 0;
}