there is no "dat" file although i write the out

the code have not output the ".dat" file ??

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include<cstdio>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<fstream>
#include<sstream>

using namespace std;

int NX;
int NY;
int i,j,n;

double U;
double DF;
double v[100][100];
double w;
const double pi=3.1415926;
double a,b;

void init();
void evolution();
void output(int m);
//void Error();

int main()
{
	using namespace std;

	init();
	for(n=0;;n++)
	{
		evolution();
		//Error();
		cout<<"\nThe"<<n<<"th DF is: "<<setiosflags(ios::scientific)<<DF;

	
		if(DF<1.e-5) 
		{
			output(n);
			break;
		}
	}
	system("pause");
	return 0;
}

void init()
{
	cout<<"U=";
	cin>>U;
	cout<<"NX=";
	cin>>NX;
	cout<<"NY=";
	cin>>NY;

	w=2-pi*sqrt(2*(NX*NX+NY*NY))/(NX*NY);

	for(i=0;i<NX;i++)
		for(j=0;j<NY;j++)
			v[i][j]=0.0;
		for(j=1;j<NY-1;j++)
			v[0][j]=U;
}

void evolution()
{
	for(i=1;i<NX-1;i++)
		for(j=1;j<NY-1;j++)
		{
			a=v[i][j];
			b=0.25*(v[i+1][j]+v[i][j+1]+v[i-1][j]+v[i][j-1]);
			a=a+w*(b-a);
			DF=fabs(b-a);
			v[i][j]=a;
		}
}

void output(int m)
{
	int num=0;
	std::cout<<"\nThe evlution degree is:"<<n<<endl;
	std::cout<<"The electric potential distribution is:"<<endl;

    for(i=0;i<NX;i++)
		for(j=0;j<NY;j++)
		{
			    std::cout<<v[i][j]<<" ";
				num++;
				if(num%(NX)==0) cout<<endl;
		}


	ostringstream name;
	name<<"electric potential distribution_"<<NX<<"*"<<NY<<".dat";
	ofstream out(name.str().c_str());
	for(i=0;i<NX;i++)	
		for(j=0;j<NY;j++)
		{
			out<<v[i][j]<<" ";
			num++;
			if(num%(NX)==0) out<<endl;
		}

}
https://msdn.microsoft.com/library/aa365247
× Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following:
    The following reserved characters:
        < (less than) 
        > (greater than) 
        : (colon) 
        " (double quote) 
        / (forward slash) 
        \ (backslash) 
        | (vertical bar or pipe) 
        ? (question mark) 
        * (asterisk)
Look at line 97.
Last edited on
oh thank you , i changed the "* (asterisk)" with a available character , then i get the "dat" dile. thank you very much !
Topic archived. No new replies allowed.