Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
user specified input file in c++
Name: scott Date: March 10, 2003 at 21:31:05 Pacific OS: xp pro CPU/Ram: 800mhz t-bird, 256 pc133
Comment:
my c++ assignment requires me to have the user enter a string and search a file for number of occurences. this isn't too hard except that the user is supposed to enter the name of the file to input from and output to in a string. using ifstream, how can I open a file selected by a string. eg:
Name: borelli34 Date: March 10, 2003 at 23:43:31 Pacific
Reply:
The preferred method will differ depending upon what compiler and version you are using.
borelli34
0
Response Number 2
Name: scott Date: March 10, 2003 at 23:57:38 Pacific
Reply:
I just want to know the syntax. it would work for all c++ regardless. it's just a simple console application. how can I have a user enter a string, and use that string to choose the file to take input from?
0
Response Number 3
Name: Don Arnett Date: March 11, 2003 at 11:06:50 Pacific
Reply:
I'm a C programmer who has learned C++ but has never converted to using C++ I/O (cin/cout). I continue to use C I/O (scanf(), fgets(), printf(), etc), so I'm not well versed in cin syntax.
But, basically you just want to let the user input a string, which I would imagine that you've done before, then pass that string to the open method.
char filename[50];
cin >> filename; // remember I don't use cin so adjust this syntax if it's wrong
input.open(filename);
It should be as easy as that.
0
Response Number 4
Name: scott Date: March 13, 2003 at 10:30:29 Pacific
Summary: How do you read disk files in C++? I have a book that tells you how but it's way to confusing. I understand writing to them but I can't read from it. I know it has something to do with Steam Input/Out...
Summary: I have written a code to retrive data from a file in C++,as follows cStud S; while(!f.eof()) { f.read((char*)&S,sizeof(S)); coutS; } where cStud is any class of mine and f is an object of ifstre...
Summary: Ok here is the deal: subject: Writing data to a file in C problem: I need to be able to write the data as the program is running not just when I close the file. example: Im running a packet sniffer...