Hi. I am using Code::Blocks 10.05 installed on my flash drive. I have a program that compiles and runs correctly on the flash drive. But when I copy and paste the program executable to the desktop, it works in some cases and not in others. Here is the code which I think might be causing the problem, although I can't figure out why:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
while(true)
{
std::cout<<"Enter input file name (save excel sheet as a text file): ";
getline(std::cin,line);
if(line[line.size()-4]=='.'&&line[line.size()-3]=='t'&&line[line.size()-2]=='x'&&line[line.size()-1]=='t')
InputFileName=line;
else
InputFileName=line+".txt";
infile.open(InputFileName.c_str());
if(!infile)
{
std::cout<<"\n\t\t File does not exists.\n\n";
infile.clear();
}
else
{
if(line[line.size()-4]=='.'&&line[line.size()-3]=='t'&&line[line.size()-2]=='x'&&line[line.size()-1]=='t')
{
OutputFileName=line.replace(line.size()-4,4,".csv");
break;
}
else
{
OutputFileName=line+".csv";
break;
}
}
}
|
The purpose of this part of the code is to determine whether or not the user has typed a filename with the extension or not, and then choose an appropriate course of action to open the file.
Here's the problem. I have a text file called 'input' saved on the desktop. When I run the program from the desktop and type 'input.txt' when prompted for the input file name, the program runs correctly. But when I type 'input', it does not. When I enter data at a later point in the program, it prints output from one of my functions endlessly until the program crashes.
Thanks.
EDIT: When I open the .cpp file on the desktop and run the program from there, it works. It is only when I open the .exe file directly when this problem arises. I am just so confused right now.
EDIT: Also, just changing the name of the program executable gets rid of the problem...what is going on?