Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jordy664

macrumors newbie
Original poster
Dec 7, 2010
3
0
This is the beginning of the code i have and it keeps returning the "cannot open file" and i cannot see why...

Code:
#include <fstream> 
#include <cstdlib> 
#include <iostream> 
#include <iomanip> 
#include <math.h>

using namespace std; 

#define MAXD 100 

ifstream in_file; 
ofstream out_file;

void read_input(int& NJ, double COORD[MAXD][2], int& NS, int MSUP[MAXD][3], int& NMP, double EM[MAXD], int& NC, double CP[MAXD], int& NM, double MPRP[MAXD][4], int& NLJ, int JP[MAXD], double PJ[MAXD][2]);
void Struct_Stiffness(double KL[4][4], double L, double E, double A, double C, double S);

int main()
{
	int NJ, NS, NMP, NC, NM, NLJ;
	double COORD[MAXD][2]={0};
	int MSUP[MAXD][3]={0};
	double EM[MAXD]={0};
	double CP[MAXD]={0};
	double MPRP[MAXD][4]={0};
	int JP[MAXD]={0};
	double PJ[MAXD][2]={0};
	double Stiff[MAXD][MAXD]={0};

	int NP[4];
	
	int el=0;
	int i, j;
	
	in_file.open("input.txt");
	out_file.open("output.txt");
	
	
	if(in_file.fail()) 
	{ 
		cout << "The file cannot be opened." << endl; 
		exit(1); 
	} 	
	
	read_input(NJ, COORD, NS, MSUP, NMP, EM, NC, CP, NM, MPRP, NLJ, JP, PJ); 
	..................
 
Last edited by a moderator:
Two thoughts:

1. Print the working directory. Make sure it's what you expect.
If it's not what you expect, change the settings of the executable. The working directory is set under the General tab of the Executable's info pane.


2. Remove these in the build settings:
  • _GLIBCXX_DEBUG=1
  • _GLIBXX_DEBUG_PEDANTIC
https://forums.macrumors.com/threads/867839/
https://forums.macrumors.com/threads/863761/
https://forums.macrumors.com/threads/837748/
https://forums.macrumors.com/threads/796818/
https://forums.macrumors.com/threads/780440/
.. 867839 lists specific steps to take.
.. 796818 notes input problems.
 
Last edited:
Two thoughts:

1. Print the working directory. Make sure it's what you expect.
If it's not what you expect, change the settings of the executable. The working director is set under the General tab of the Executable's info pane.


2. Remove these in the build settings:
  • _GLIBCXX_DEBUG=1
  • _GLIBXX_DEBUG_PEDANTIC
https://forums.macrumors.com/threads/867839/
https://forums.macrumors.com/threads/863761/
https://forums.macrumors.com/threads/837748/
https://forums.macrumors.com/threads/796818/
https://forums.macrumors.com/threads/780440/
.. 867839 lists specific steps to take.
.. 796818 notes input problems.

Since these macros come up so often I made a guide (so I wouldn't have to track down links). It should show up at the top of the forum.
http://guides.macrumors.com/Why_simple_CPlusPlus_programs_in_XCode_crash_when_using_std::string

-Lee
 
Since these macros come up so often I made a guide (so I wouldn't have to track down links). It should show up at the top of the forum.
http://guides.macrumors.com/Why_simple_CPlusPlus_programs_in_XCode_crash_when_using_std::string

I forgot about that. I had the URLs in my Frequently Pasted URLs file, so that's what I used.

The guide says "crash", though, when the problem may not be a crash.

Also, it doesn't say what the problematic macro definitions are.

Finally, it doesn't reference any of the articles that describe the problem and solution.
 
It is in the working directory because when the output file is opened that is where it appears... sorry im quite new to this
 
I now realize that the program continues to run (loop) as well and i have to stop it manually... does this have something to do with it?
 
Your posted code doesn't have a loop. If you want anyone to comment on that code, you'll have to post it.

I can tell by the posted code that you've got a lot of data being parsed, so it's entirely possible that the parsing is broken. But without seeing code, all anyone can do is guess.

If you just want to find out if the input file opened, then add a cout << "It Opened" to your code, right after the if() that tests for failure.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.