Reputation: 79
I'm trying to write a program. The first file will be opened for input and the second file will be opened for output. (It will be assumed that the first file contains sentences that end with a period.) The program will read the contents of the first file and change all the letters to lowercase except the first letter of each sentence, which should be made uppercase. The revised contents should be stored in the second file.
I've been able to get my code to work in that I successfully converted the contents in input.txt to the above requirements (all sentences are lowercase except for the first word in each sentence). However, this content does not appear in output.txt
Both input.txt
and output.txt
are in the same directory next to main.cpp
.
I tried using different IDEs but that didn't do anything. I also tried moving around the location of output.txt but that did nothing also.
SAMPLE INPUT: google's homepage includes a button labeled "I'm Feeling Lucky". When a user types in a search AND clicks on the button the user will be taken directly to the first search result, bypassing the search engine results page.
SAMPLE OUTPUT: Google's homepage includes a button labeled "i'm feeling lucky". When a user types in a search and clicks on the button the user will be taken directly to the first search result, bypassing the search engine results page.
string inFileName, outFileName;
string line;
char c;
cout << "Enter input file name: ";
cin >> inFileName;
fstream fin, fout;
fin.open(inFileName.c_str(), ios::in);
fout.open(outFileName.c_str(), ios::out);
if (fin.fail())
{
cout << "INPUT FILE DOES NOT EXIST (DNE)\n";
system("pause");
return 1;
}
Nothing shows up in output.txt
(it's blank). From what I've noticed this command fout << line << "." << endl;
isn't doing anything.
[Here's another screenshot]that shows what's in my terminal as well as what is in input.txt
and output.txt
:
You'll notice that in the terminal the proper conversion is shown but I am unable to get that text in the terminal into output.txt
.
Upvotes: 1
Views: 1021
Reputation: 384
I agree with all the above answers and they are appropriate for all the users. In my case though there was a segmentation fault that led to file write failure. Try rectifying any segmentation faults.
Upvotes: 0
Reputation: 1582
After every source code is compiled, a executable program is created. On Windows, it has .exe
extension. The program should have the same name from your source code.
Try to find where it is created. It can be inside the temp
folder or maybe where Visual Studio
is installed.
Your text document (.txt
) file for storing output has to be in the same directory with the executable.
I executed your program on my device (on Code::Blocks IDE though). It went as it should.
Upvotes: 2