Hello , i am new on this <fstream>, i want to make a program which will asks the exact key word from the user , if user types it wrong ,it should give error.What is my mistake here. Thank you,
Also , you don't indicate whether the first two files are to be used for input or output? If the file is for input it should already exist. In that case use ifstream.
Hello again and Thank you!
i tried to make what you mentioned but i am still having troubles about start working the program, Concept of the program , it should open "songs.txt" file , if user types the exact "songs.txt".
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string songfile;
cout << "Please enter a filename for the Songs file :" << endl;
cin >> songfile;
fstream filesng;
filesng.open("songs.txt");
if (filesng.is_open())
{
string votefile;
cout << "Please enter a filename for Votes\n file :" << endl;
cin >> votefile;
fstream filevt;
filevt.open("Votes.txt");
if (filevt.is_open())
{
string outfile;
cout << "Please enter a filename for Output\n file :" << endl;
cin >> outfile;
fstream fileop;
fileop.open("output.txt");
if (fileop.is_open())
{
cout << "Results are in the file : output.txt" << endl;
}
else
{
cout << "Cannot open the Output file !" << endl;
}
}
else
{
cout << "Cannot open the Votes file !" << endl;
}
}
else
{
cout << " Cannot open the Songs file !" << endl;
}
return 0;
cin.get();
cin.ignore();
}
Concept of the program , it should open "songs.txt" file , if user types the exact "songs.txt".
If the user must enter "songs.txt" then test it directly:
1 2 3 4 5 6 7 8 9 10 11
string songfile;
cout << "Please enter a filename for the Songs file :" << endl;
cin >> songfile;
if (songfile != "songs.txt")
{
cout << "Sorry, that name is incorrect\n";
}
else
{
// etc.
}