|
-
October 28th, 2008, 01:25 AM
#1
Help, cannot figure this out
I am trying to get a program that will allow a user to input a filename, then the program will search through the file for < and > and change them to < and >
then this will then output a newfile with the changes
I have tried but whenever I run it asks for the file name which I input a file, then asks for the name I should give the output which I do. Then it closes. It does create a new file but the new file has nothing inside of it.
I was wondering what is wrong with my code since it seems as the program never opens the input file.
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream outStream;
string fileoutput_name;
string filename;
cout << "Name your file ";
cin >> filename;
getchar ();
fstream file( filename.c_str() );
string searchString("<");
string searchString2 (">");
string replaceString( "<");
string replaceString2(">");
string::size_type i = 0;
while ( (i = filename.find(searchString, i)) != string::npos ) {
filename.replace( i, searchString.size(), replaceString );
i++;
}
while ( (i = filename.find(searchString2, i)) !=string::npos ) {
filename.replace( i, searchString2.size(), replaceString2 );
i++;
}
cout << " What would you like to name the file to where these\n"
<< " random numbers will be stored?\n";
cin >> fileoutput_name;
outStream.open(fileoutput_name.c_str());
getchar ();
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|