Howdy. Just got serious about learning C++ so i decided the best way to learn would be through practice. So i'm making a progam that takes the tutorials from the home page (cprogramming.com) and displays them when you request them.
my code:
//Program is for personal use only. Lessons property of cprogramming.com.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char fileName [80];
char buffer [10000];
int page;
cout<<"1.Lessons: \n";
cout<<"2.Intro to C++ \n";
cout<<"3.If statements \n";
cout<<"4.Loops \n";
cout<<"5.Functions \n";
cout<<"6.Switch case \n";
cout<<"7.Pointers \n";
cout<<"8.Structures \n";
cout<<"9.Arrays \n";
cout<<"10.Strings \n";
cout<<"11.File I/O \n";
cout<<"12.Typecasting \n";
cout<<"13.classes \n";
cout<<"14.Inline functions \n";
cout<<"15.Command line arguments \n";
cout<<"16.Linked Lists \n";
cout<<"17.Recursion \n";
cout<<"18.Variable argument lists \n";
cout<<"19.Binary Trees \n";
cout<<"20.Inheritance \n\n";
cout<<"Please enter lesson number \n";
cin>> fileName; //filename is also used as lesson number
ifstream fin(fileName);
if (fin)
{
cout<<"Current File Contents:\n";
char ch;
while (fin.get(ch))
cout<<ch;
cout<<"\n***End of File contents.***\n";
}
fin.close();
}
I have it working to display the file, but it's a .txt file and i need to enter .txt everytime. Is there a way so i can just do the filename without .txt...say add .txt in the code somewhere? Hopefully you guys understand what i'm getting at. Thanks.