no error but no output

I wrote this code. It does not give any output. Output screen opens but it is an empty window
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "stdafx.h"
using namespace std;
int main(){
	float mainpress,maintemp,mainpow,allvariables,diff,mindist=100000;
	vector<float> list;
	vector<float>presslist;
	vector<float>templist;
	vector<float>powerlist;
	vector<float>difflist;
	ifstream myfile ("example.txt");
	ofstream yourfile;
	yourfile.open("power.txt");
	int j,i,neighbour;
	for( j=0;j<7500;j++)
		{	myfile >> allvariables;
	list.push_back(allvariables);}//reading datas from file and sending to vector
	for( j=0;j<7500;j++)
		{	int div,mod=j%3;
			div=j/3+1;
			if(mod==0){
				maintemp=list.at(j) ;
				templist.push_back(maintemp) ;	}		
			if(mod==1){
				mainpress = list.at(j) ;	
				presslist.push_back(mainpress);}
			if(mod==2){
				mainpow= list.at(j);
				powerlist.push_back (mainpow);}}//sorting datas as power temp and pressure
		for(i=0;i<2500;i++){
			for(j=0;j<2500;j++){
				diff=sqrt(((templist.at(i)-templist.at(j))*(templist.at(i)-templist.at(j)))+((presslist.at(i)-presslist.at(j))*(presslist.at(i)-presslist.at(j))));
				if(i==j)
					diff=100000;
				difflist.push_back(diff);}//findig distances and listing them
			for(j=0;j<2500;j++){
				if(difflist.at(j)<mindist){
				mindist=difflist.at(j);
				neighbour=j;}}
			mindist=100000;
			yourfile << powerlist.at(neighbour)<< "\n"; 
			myfile.close();
			difflist.clear();
		}
	cout<<"nn";
    system("pause");
	return 0;
}
Presumably you're expecting to see "nn" on screen, as that's the only thing you output to screen. I expect it's being buffered. Replace
cout<<"nn";
with
cout<<"nn" << endl;
the problem with cout is okey now thank you but it doesn't write on file still.
How do you know it's meant to? It's about time you started debugging for yourself.

For example, put this:
cout << "Now writing to file " << endl;
on line 40 so that you can see if your code ever actually gets to writing output to file.

If it doesn't, then you know that the code is never reached and you can put some logging lines earlier to see what happens so that it never gets there.
ok i tried and it worked thank you. the problem is about the issue that there are for loops in the code and takes a little time to debug and i look very soon to the file so ş can't see the output.

But now there is no problem
Topic archived. No new replies allowed.