PDA

View Full Version : File I/O




iWill
Feb 25, 2007, 03:45 PM
Sry if this is too windows specific but i really need help... So I'd like to scan program files and add the names of each program in a file with each of their paths. Is it possible? This is where i"m stuck:

#include <iostream>
#include <windows.h>
#include <fstream>
using namespace std;

int main()
{
int S1, S2;
void list();
void data();
char word[25];

cout << "\t\t *****Ultimate App Launcher*****\n\n";
cout << "[1] To Launch An App, [2] To Add an App To The List";
cin >> S1;

switch (S1)
{

case 1:
list();
cout << "Now Enter The Number Matching The App You Want To Launche";
cin >> S2;






void list()
{
ifstream File("Name.txt");

char txt;
while(!File.eof())
{
File.get(txt);
cout << txt;
}

if (!File)
{
cout << cout << "Cannot Open File. You Are Missing a File of Name **Name.txt**\n\nLocate It, Then Place It Next To The Program File.\n\n";
return 1;
}

File.close();
}
I'd like to know if i can directly read from program files, and how i could associate each app to a number so that the user only needs to type in the number to launch his application.
Thanks in advance



Eraserhead
Feb 25, 2007, 04:06 PM
What language is it? Sorry if this is a stupid question :o.

PS Please indent your code, it helps with reading it.

iWill
Feb 25, 2007, 04:13 PM
Oh yea sry for not precising...it's in C++
For this program i was also thinking of dedicating one line to the program name and then the next line to it's path in the File I/O...like that each line with an even number would correspond to the program name and vice versa for the path of each program...would this be feasible?

iWill
Feb 26, 2007, 05:02 AM
Ok....another more precise question (sorry i know i'm being kinda vague):
is it possible to compute the line numbers of a text file in C++? So that when the user enters 2, my program would read line number two of the text file?

superbovine
Feb 26, 2007, 07:52 AM
Ok....another more precise question (sorry i know i'm being kinda vague):
is it possible to compute the line numbers of a text file in C++? So that when the user enters 2, my program would read line number two of the text file?

http://msdn2.microsoft.com/en-us/library/system.io.streamreader.readline(VS.71).aspx

straight c++
http://www.cs.mun.ca/~gstarkes/3710/c++/lecture2.html