You are here:

C++/file process

Advertisement


Question
i want to insert an existing or not file's name from the kayboard to be associated with the stream and to be able to process the file.
example:
ifstream a;
cin>>file_name;
a.open(file_name); ect... i cant find what to put in filename to make it work.. Thanx for the hope of help by your existance only.

Answer
Hello Andrew, thank you for the question.

You look to be pretty close.

std::string fileName;
std::cout << "Enter a file name";
std::cin >> fileName;

ifstream a(fileName.c_str());
// file is open. Put data in file
a.close();

I hope this information is helpful.

- Eddie

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Eddie

Expertise

I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.

Experience

I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 About.com. All rights reserved.