Hello ineedhelp2,
PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
I found the second link to be the most help.
Given a file name of "File Name", notice the space,
cin >> inputName;
will only input up to and including the first white space leaving "Name" in the input buffer for the next "cin >>" or whatever is used. If the file name happens to be "FileName" this will work fine.
I suggest using
std::getline(std::cin", inputName)
for the best results.
Then the lines:
1 2
|
inFile.open(inputName);
if (!inFile.open(inputName)
|
You are trying to open the same file stream twice. What I see most often is:
if (!inFile)
will suffice. And you are missing a closing parenthesis on your code not that it makes much difference.
An implementation of Thomas1965's loop will work here.
Something else to think about. Will the user be entering the complete file name with extension or will the program need to provide the extension?
One last point it is generally better to post the whole code that can be compiled as there may be other problems that may need addressed.
Hope that helps,
Andy