this is a really strange one since it doesn't make sense why the program just starts running then shuts down without executing the system("PAUSE") at the end.

here is the source code, thanks in advance to any help.

#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

int main() 
{

string LogicMolecule;
string ExecutableCodeName;
int size;
vector<string> LogicMolecules;
	
cout << "Execute: ";
cin >> ExecutableCodeName;
system("cls");

ExecutableCodeName = ExecutableCodeName + ".code";
    
ifstream ExecutableCodeFile;
ExecutableCodeFile.open(ExecutableCodeName.c_str());
	
if (!ExecutableCodeFile.is_open()) 
{
cout << "error: can't open executable code";
cout << "\n";
system("PAUSE");
}
	
while (ExecutableCodeFile >> LogicMolecule) 
{
	LogicMolecules.push_back(0);
}

ExecutableCodeFile.close();
size = LogicMolecules.size();
cout << size;
cout << "\n";
system("PAUSE");

}

Recommended Answers

All 9 Replies

try to replace

system("pause');

with..

cin.ignore();

nah thanks but that didnt work

It worked fine for me. Try adding this at the end instead.

cin.ignore(100, '\n');
cin.get();

Chris

If it can't open it then why do you continue to use it afterward?

file open
if(is open)
{
  do stuff
  close
}
else
{
   print "Error"
}

You're also missing a return.

that did absolutely nothing, but thanks for trying. I think the problem is that its not getting to the code for some reason maybe the while loop or something? i dunno but chris you prolly hit the code that said error cant open executable code.

that did absolutely nothing, but thanks for trying. I think the problem is that its not getting to the code for some reason maybe the while loop or something? i dunno but chris you prolly hit the code that said error cant open executable code.

Follow MosaicFuneral's Advice. the reason your program is terminating is due to the fact you have a vector of type string and you are trying to push an integer into it, see the problem?

Chris

yeah didn't realize it was that integer thing, thanks man.

#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

int main() 
{

string LogicMolecule;
string ExecutableCodeName;
int size;
vector<string> LogicMolecules;
	
cout << "Execute: ";
cin >> ExecutableCodeName;
cin.ignore(); // wana ignore the enter press here        < -------------------------------------
system("cls");

ExecutableCodeName = ExecutableCodeName + ".code";
    
ifstream ExecutableCodeFile;
ExecutableCodeFile.open(ExecutableCodeName.c_str());
	
if (!ExecutableCodeFile.is_open()) 
{
cout << "error: can't open executable code";
cout << "\n";
system("PAUSE");
}
	
while (ExecutableCodeFile >> LogicMolecule) 
{
	LogicMolecules.push_back(0);
}

ExecutableCodeFile.close();
size = LogicMolecules.size();
cout << size;
cout << "\n";
system("PAUSE");

}

used to have that problem allot. After you call
cin >> ...;
it doesent keep the '\n' you entered
so you have to ignore that, or that gets taken down and screws up everything else : )

Hope it works..


BTW it wasnt solved so thoght i could still help : /
but i guess they answerd it for you alrdy.

use..

//...
fflush(stdin);
system("pause");
//...
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.