Hi I'm writing a function for a program that allows a student to copy a template text file. This function checks the user's input to see if his desired template is allowed for his class.
I'm getting the error "Comparison with string literal results in unspecified behavior" on lines 21 and 25. I have done "cout << name" to verify that variable is storing correctly, which it is, so I know that's not the problem. So I was wondering if yall might have an idea of a fix.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
//TEMPLATE CHECK
//First you check to see if the student is allowed to use the template
int templateCheck()
{
//Declare file name variable
char name[256];
//Prompt for user input
cout << "Enter file name: ";
//Cin user input
cin >> name;
//Begin check
//CS221 is the first template you can't use
if(name == "/home/cs221Temp.txt")
cout << "You are not allowed to use CS221 templates./n";
//CS 321 is the other template you can't use
else if (name == "/home/cs321Temp.txt")
cout << "You are not allowed to use CS321 templates./n";
//Any others are okay (I commented these out since I'm just working on this function by itself)
//else
//copyTemplate();
return 0;
}
Aucun commentaire:
Enregistrer un commentaire