when i m using this code: its not complete code..assume everything is right...

for(int result=0;result<g;result++)
		{
		u1+=((a[result].real_z1*tw[result])/sumd);
		u2+=((a[result].imaginary_z1*tw[result])/sumd);
		u3+=((a[result].real_z2*tw[result])/sumd);
		u4+=((a[result].imaginary_z2*tw[result])/sumd);
		}

cout<<"\n""Value of U1:"<<setiosflags(ios::scientific)<<setw(10)<<setprecision(8)<<u1;
cout<<"\n""Value of U2: "<<setiosflags(ios::scientific)<<setw(10)<<setprecision(8)<<u2;
cout<<"\n""Value of U3: "<<setiosflags(ios::scientific)<<setw(10)<<setprecision(8)<<u3;
cout<<"\n""Value of U4: "<<setiosflags(ios::scientific)<<setw(10)<<setprecision(8)<<u4;

ofstream abc;
abc.open("result.txt", ios::out | ios::ate);
abc<<endl<<endl;
abc<<"Data at position [ "<<i<<" , "<<j<<" ]"<<endl;
abc<<setiosflags(ios::scientific)<<setw(10)<<setprecision(8)<<u1<<"		";
abc<<setiosflags(ios::scientific)<<setw(10)<<setprecision(8)<<u2<<"		";
abc<<setiosflags(ios::scientific)<<setw(10)<<setprecision(8)<<u3<<"		";
abc<<setiosflags(ios::scientific)<<setw(10)<<setprecision(8)<<u4<<"		";

abc.close();

I am getting several errors like:

1>c:\tcwin45\bin\finalpro.cpp(126) : error C2653: 'ios' : is not a class or namespace name
1>c:\tcwin45\bin\finalpro.cpp(126) : error C2065: 'scientific' : undeclared identifier
1>c:\tcwin45\bin\finalpro.cpp(126) : error C3861: 'setiosflags': identifier not found
1>c:\tcwin45\bin\finalpro.cpp(126) : error C3861: 'setw': identifier not found
1>c:\tcwin45\bin\finalpro.cpp(126) : error C3861: 'setprecision': identifier not found
1>c:\tcwin45\bin\finalpro.cpp(127) : error C2653: 'ios' : is not a class or namespace name
1>c:\tcwin45\bin\finalpro.cpp(127) : error C3861: 'setiosflags': identifier not found
1>c:\tcwin45\bin\finalpro.cpp(127) : error C3861: 'setw': identifier not found
1>c:\tcwin45\bin\finalpro.cpp(127) : error C3861: 'setprecision': identifier not found
1>c:\tcwin45\bin\finalpro.cpp(128) : error C2653: 'ios' : is not a class or namespace name
1>c:\tcwin45\bin\finalpro.cpp(128) : error C3861: 'setiosflags': identifier not found
1>c:\tcwin45\bin\finalpro.cpp(128) : error C3861: 'setw': identifier not found
1>c:\tcwin45\bin\finalpro.cpp(128) : error C3861: 'setprecision': identifier not found
1>c:\tcwin45\bin\finalpro.cpp(129) : error C2653: 'ios' : is not a class or namespace name
1>c:\tcwin45\bin\finalpro.cpp(129) : error C3861: 'setiosflags': identifier not found
1>c:\tcwin45\bin\finalpro.cpp(129) : error C3861: 'setw': identifier not found
1>c:\tcwin45\bin\finalpro.cpp(129) : error C3861: 'setprecision': identifier not found
1>c:\tcwin45\bin\finalpro.cpp(131) : error C2065: 'ofstream' : undeclared identifier
1>c:\tcwin45\bin\finalpro.cpp(131) : error C2146: syntax error : missing ';' before identifier 'abc'
1>c:\tcwin45\bin\finalpro.cpp(131) : error C2065: 'abc' : undeclared identifier

please help me to solve it...

Recommended Answers

All 11 Replies

You need to #include <iomanip>

i m getting

error c3861: 'clrscr': identifier not found..

how to solve this?

i m getting

error c3861: 'clrscr': identifier not found..

how to solve this?

That's a non-standard function not supported by MS, for equivalent functionality, see http://support.microsoft.com/kb/q99261/

is it possible that i can post here my whole project...not big though..and u can solve the errors???they all r general...u will not take much time...if it take, you can leave..
plz can you help me???

is it possible that i can post here my whole project...not big though..and u can solve the errors???they all r general...u will not take much time...if it take, you can leave..
plz can you help me???

Well, you can give it a try of course and see how it goes.
The other (suggested) method, is to work it out one error at time, i.e. recompile after every fix you think you've made. And when stuck on an error, post a question here ...

1>c:\tcwin45\bin\finalpro.cpp(137) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'int'
1> c:\program files\microsoft visual studio 8\vc\include\ostream(735) : see declaration of 'std::operator <<'

I am getting around 10 errors of this type..
what should i do now??

is fscanf not valid in visual c++?


might be i have just copy paste this project from borland c++, then i am getting such problem..is it so?

this is my whole program..in this i have tried to read data from a txt file, selected some data from it,done calculations on it and have saved the result in another text file...

please help me frnd.....

#include <stdafx.h>
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;
using namespace stdext;

/* some global variables to store maximum scanning area in x,y direction and grid distances */
int x,y,k,l,a,b;
/* p,q will store value to be used in calculation using formula */
float p,q;
/* global arrays to store sum of various sigmas which are used in formulae */
float distance[5000],distance1[5000],distance2[5000], tw[5000];

/* a class named as data where voltages will be stored */
class data
		{
		public:
		int x_component,y_component;
		float real_z1,imaginary_z1;
		float real_z2,imaginary_z2;
		void getdata();
		}d[5000],f[5000];

int c=0;

/* function to get data from data.txt */
void gtdata()
	{
	 FILE *fp;
	 c = 0;
	 fp=fopen("data1.txt","r");
	 if(fp==NULL)
	  {
		puts("Cannot open file");
	  }
	 while(fscanf(fp,"%d %d %e %e %e %e", &d[c].x_component, &d[c].y_component, &d[c].real_z1, &d[c].imaginary_z1, &d[c].real_z2, &d[c].imaginary_z2)!= EOF)
	 {
	  printf("%d",d[c].x_component);
	  printf("%d",d[c].y_component);
	  printf("%e",d[c].real_z1);
	  printf("%e",d[c].imaginary_z1);
	  printf("%e",d[c].real_z2);
	  printf("%e",d[c].imaginary_z1);
	  c++;
	  }
	  fclose(fp);
	 }




/* function to calculate volatges at different parts of the grid or you can say to calculate u1,u2,u3,u4 */
void calculation(data a[], int i, int j,int g)
	{
	int w,l,f,g1;
	float h,u,cw;
	float sum=0,sum1=0,sum2=0,sumd=0;
	/* this for loop will calculate how many total no. of objects will affect a particular grid position i ,j */
	/* loop to calculate the distance between m1 and xi */
	for(int s=0;s<g;s++)
		{
		sum=0;
		sum1=0;
		w=pow((a[s].x_component-i),2);
		l=pow((a[s].y_component-j),2);
		h=sqrt(w+l);
		/* all such ditances like m1 to i,j and m2 to i,j will be stored into an array distance1 */
		distance1[s]=h;
		/* this loop will calculate distance between m1 to m2,m3 and so on..*/
		for(int m=0;m<g;m++)
			{
			if(m!=s)
				{
				f=pow((a[s].x_component-a[m].x_component),2);
				g1=pow((a[s].y_component-a[m].y_component),2);
				u=sqrt(f+g1);
				if(u<=h)
					{
					/* this sum and sum1 are used in calculating cw1 */
					sum+=(1-(u/h));
					sum1+=((1-(u/h))* (pow(u,p)));
					}
				}
			}
		cw=((h+sum1)/(h*(1+ sum)));
		// cw1,cw2...all will be stored in an array distance
		distance[s]=cw;
		}
	// loop to calculate sum of dij to the power -q;
	for(s=0;s<g;s++)
		{
		sum2+=pow(distance1[s],-q);
		}
	// dw1,dw2 will be calculated and stored in an array of distance2
	for(s=0;s<g;s++)
		{
		distance2[s]=((pow(distance1[s],-q))/sum2);
		}
	/* total weight is calculated for all objects and stored in an array of tw */
	for(int lo=0;lo<g;lo++)
	  {
	  tw[lo]=distance2[lo]*distance[lo];
	  }
	/* sum of total weights is calculated and saved in sumd, this is used in calculating u1,u2,u3,u4 */
	for(int as=0;as<g;as++)
		{
		sumd+=tw[as];
		}
	/* the final result for a particular grid i j */
	float u1,u2,u3,u4;
	u1=u2=u3=u4=0;
	cout<<endl;
	cout<<"\n""Data at position ["<<i<<" ,"<<j<<" ]";
	for(int result=0;result<g;result++)
		{
		u1+=((a[result].real_z1*tw[result])/sumd);
		u2+=((a[result].imaginary_z1*tw[result])/sumd);
		u3+=((a[result].real_z2*tw[result])/sumd);
		u4+=((a[result].imaginary_z2*tw[result])/sumd);
		}

	cout<<"\n""Value of U1: "<<setiosflags(ios::scientific)<<setw(10)<<setprecision(8)<<u1;
	cout<<"\n""Value of U2: "<<setiosflags(ios::scientific)<<setw(10)<<setprecision(8)<<u2;
	cout<<"\n""Value of U3: "<<setiosflags(ios::scientific)<<setw(10)<<setprecision(8)<<u3;
	cout<<"\n""Value of U4: "<<setiosflags(ios::scientific)<<setw(10)<<setprecision(8)<<u4;

		ofstream abc;
		abc.open("result.txt", ios::out | ios::ate);
		abc<<endl<<endl;
		abc<<abc<<"Data at position [ "<<i<<" , "<<j<<" ]"<<endl;
		abc<<setiosflags(ios::scientific)<<setw(10)<<setprecision(8)<<u1<<"		";
		abc<<setiosflags(ios::scientific)<<setw(10)<<setprecision(8)<<u2<<"		";
		abc<<setiosflags(ios::scientific)<<setw(10)<<setprecision(8)<<u3<<"		";
		abc<<setiosflags(ios::scientific)<<setw(10)<<setprecision(8)<<u4<<"		";

		abc.close();

 }
/* function to search which object will affect the grid volatage */
void selection()
	{
	int g=0;
	/* i and j are grid positions which will run from 0,0 till the max. scanning area */
	/* k is used to scan all the stored data to know which object will be used to calculate grid volatages */
	for(int j=0;j<y;j=j+l)
		{
		for(int i=0;i<x;i=i+k)
			{
			g=0;
			 for( int k=0;k<c;k++)
				{
				/* a and b are the deltax and deltay. If an object comes under this area, it will affect grid volatages.Total objects are stored in f array */
				if(abs(d[k].x_component-i) <=a )
					{
					if(abs(d[k].y_component-j) <=b )
						{
						f[g]=d[k];
						g++;
						}
					}
				}
			 calculation(f,i,j,g);
			 }
		}
	}
void main()
		{
		system("cls");
		/* initialising all objects of class data to zero */
		cout<<"Entered  data is ""\n";
		gtdata();
		cout<<"\n""Enter the maximum value of scanning in x direction";
		cin>>x;
		cout<<"\n""Enter the maximum value of scanning in y direction";
		cin>>y;
		cout<<"\n""Enter the value of distance between the grids in x axis";
		cin>>k;
		cout<<"\n""Enter the value of distance between the grids in y axis";
		cin>>l;
		cout<<"\n""Enter the value of deltax";
		cin>>a;
		cout<<"\n""Enter the value of deltay";
		cin>>b;
		cout<<"\n""Enter the value of p";
		cin>>p;
		cout<<"\n""Enter the value of q";
		cin>>q;
		selection();
		}

To compile your program w/o errors make some transformations:

1. Replace all float to double (use IDE Replace cmd). Never use float type in scientific/engineering calculations - use only double.

2. Correct two for loop headers

for(int s=0;s<g;s++) // add int s declaration

3. Move standard library includes (#include <...>) from the main file to stdafx.h. Add #include <fstream> in stdafx.h. Always place these includes to stdafx.h. Your own includes (#include "...") place after #include "stdafx.h".

4. Delete using namespace std and stdext directives. Add these directives and two function definitions:

#include "stdafx.h"
// Your main file started here
using std::ios;
using std::cout;
using std::cin;
using std::endl;
using std::setw;
using std::setprecision;
using std::ofstream;

inline double pow(int x, int n)
{
    int y = x;
    while (--n > 0)
        y *= x;
    return y;
}

inline double sqrt(int x)
{
    return sqrt((double)x);
}

Now compile your program. You will get two warnings about fopen and fscanf. Of course, no need to use these C style routines to get data from a file. Better rewrite it later with ifstream...

Yet another four warnings refers to double to int conversion. Regrettably, you declare some variables as ints but use them as doubles (for example, calculate a very strange thing as sqrt(int)). Try to revise types of these variables later.

Successful compilation... debugging started...

Good luck!

I am still getting lots of errors.Can you please repeat your 3 rd point.I cant understand it.

Well, let's try again...
Now your main file started with:

#include <stdafx.h>
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;
using namespace stdext;

It's wrong (must be #include "stdafx.h" ).

Obviously, it's MS Visual C++ project (stdafx.h is MS Visual C++ artifact). This IDE generated header contains all system header includes. If so, you are using so called precompiled header (a very fast compilation).

Move includes from iostream to iomanip to stdafx.h, add #include <fstream> below #include <iomanip>. Now all these <...> includes are placed in stdafx.h.

Remove using namespace directives, add using directives from my post above. Now your main file looks like:

#include "stdafx.h"
// Your main file started here
using std::ios;
using std::cout;
using std::cin;
using std::endl;
using std::setw;
using std::setprecision;
using std::ofstream;

inline double pow(int x, int n)
{
    int y = x;
    while (--n > 0)
        y *= x;
    return y;
}

inline double sqrt(int x)
{
    return sqrt((double)x);
}

Ooh! That's all...

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.