Sunday, July 12, 2009

C++, using default file name?

I'm writing a code for matrix multiplication. At one point the program asks the user to type in the file name to get the file data. If the user presses 'Enter,' I need the program to use a default file name. I can't get this part to work right. If the user inputs a file name, it works fine, but if they press enter it won't use the default name. (I'm using Visual C++ 2005 btw.) Here's the part of the code that addresses my problem:





int const size = 80;


int i, j;


char cstring[size];


char DEFAULTINPUTFILE = "input.txt";





cout %26lt;%26lt; "Please type the input file's name:";





cin %26gt;%26gt; cstring;





ifstream inputFile;





inputFile.append(cstring);





if ( cstring[0] == '\0' )





cstring = DEFAULTINPUTFILE;








inputFile.open(cstring);





Any advice (I want to understand how to do this) would be much appreciated. Thanks in advance!

C++, using default file name?
try





cstring.length() == 0;


No comments:

Post a Comment