Error in building solution in VC++ 2008

Pages: 12
Well,

Here 's the code. Remember, I'm still a beginner so its possible for me to make the mistakes too. So everybody, please chill before telling me that my code is COCKING UP

Below is the code, when I run it on VC ++, I still get my runtime error. Mind you, I get the error AFTER all the OUTPUT i.e. the entire vector has been printed out.

NO such error on Dev C++. Perhaps, someone here can tell me why.


#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
#include <vector>
#include <stdlib.h>
#include <cstdlib>


vector<double> ReadInFiles(const std::string& filename);

int main()
{  
    char endRun;
	
	vector<double> data1 = ReadInFiles("data.txt");
	for(int i=0; i <= data1.size()-1; i++)
	{ cout << data1[i] << endl;
	}
	
	cin >> endRun;
    return 1;
}



////The fuction below will read in the files. 

vector<double> ReadInFiles(const std::string& filename)
{
	ifstream myFile;
	string line;
	double num;
	vector<double> toBeReturned;
 


	myFile.open(filename.c_str());
	if(!myFile)
	{   cerr << "Unable to open file datafile.txt";
		exit(1);   // call system to stop
	}
    
    while(myFile >> num)
    { toBeReturned.push_back(num);
    }

	myFile.close();

	return toBeReturned;
}
Firstly, why are you returning 1? That makes quite a few debuggers cry.

You may also use cin.ignore() in place of cin >> char.

-Albatross
Last edited on
closed account (z05DSL3A)
A thought occurs to me, on first look at your code and the description of the error you are getting.
"Proj.exe has has stopped working"


Would I be correct in assuming that you close the window by click the red cross and not pressing return?
If so, then the 'error' is due to this. VS is not letting the window close and when Windows does not get a response from the request to close it informs you that it has stopped and will be closed.
Topic archived. No new replies allowed.
Pages: 12