473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

namespace problem

hey all
I wrote the following code which run well in g++, but when I try to
compile it in C++ builder, it report a bunch of problems, the most
frustrating one is
"[C++ Error] Unit1.cpp(1): E2282 Namespace name expected"

I attached my code, anyone can help me run this code smoothly? I really
appreciate it.
Thanks a lot
B
using namespace std;
#include <iostream>
#include <fstream>
#include <cmath>

int main(){
int Nstep=500;//must be even
int Nstepoutput=50;
ofstream input[Nstepoutput];
char buf[256];

for(int i=0;i<Nstepoutput;i++)
{
sprintf(buf,"output%d",i);
input[i].open(buf);
}

double delta_t=1.0/Nstep;
double delta_x=1.0/Nstep;
double vel[Nstep][Nstep];
double density[Nstep][Nstep];
double denvel[Nstep][Nstep];
double energy[Nstep][Nstep];
double x[Nstep];
double time[Nstep];
ofstream haha("hehe");

for(int i=1;i<Nstep+1;i++)
{
x[i-1]=double((i-1))/Nstep;
time[i-1]=double((i-1))/Nstep;
vel[0][i-1]=0; // intial velocity at time=0;
vel[i-1][0]=0;
vel[i-1][Nstep-1]=0;
density[i-1][0]=1;
density[i-1][Nstep-1]=0;
energy[i-1][0]=2.5;
energy[i-1][Nstep-1]=2;
denvel[0][i-1]=0;
denvel[i-1][0]=0;
denvel[i-1][Nstep-1]=0;
}
for(int i=1;i<Nstep/2+1;i++)
{
density[0][i-1]=1;
energy[0][i-1]=2.5;
input[0] << x[i-1] << '\t' << density[0][i-1] << '\t' <<
energy[0][i-1] << endl;
}
for(int i=Nstep/2+1;i<Nstep+1;i++)
{
density[0][i-1]=0.125;
energy[0][i-1]=2;
input[0] << x[i-1] << '\t' << density[0][i-1] << '\t' <<
energy[0][i-1] << endl;
}

for(int i=0;i<Nstep-2;i++){

for(int j=1;j<Nstep-2;j++)
{

density[i+1][j]=-(density[i][j+1]*vel[i][j+1]-density[i][j-1]*vel[i][j-1])/2.0/delta_x*delta_t+(density[i][j+1]+density[i][j-1])/2.0;
//lax method for first different equation

denvel[i+1][j]=-(denvel[i][j+1]*vel[i][j+1]+0.4*density[i][j+1]*energy[i][j+1]-denvel[i][j-1]*vel[i][j-1]-0.4*density[i][j-1]*energy[i][j-1])/2.0/delta_x*delta_t+0.5*(

denvel[i][j+1]+denvel[i][j-1]);

energy[i+1][j]=(-(vel[i][j+1]*(1.4*density[i][j+1]*energy[i][j+1]+0.5*density[i][j+1]*vel[i][j+1]*vel[i][j+1])-vel[i][j-1]*(1.4*density[i][j-1]*energy[i][j-1]+0.5*density[i][j-1]*vel[i][j-1]*vel[i][j-1]))/2.0/delta_x*delta_t+0.5*(density[i][j+1]*(energy[i][j+1]+0.5*vel[i][j+1]*vel[i][j+1])+density[i][j-1]*(energy[i][j-1]+0.5*vel[i][j-1]*vel[i][j-1])))/density[i+1][j]-0.5*vel[i+1][j]*vel[i+1][j];

// density are not zero at all,but how to protect program from
potential zero bug

}
cout << i << "\t" << i/5 << "\t" << i/5.0 << endl;
getchar();

if(i/5==i/5.0){
for(int jj=0;jj<Nstep;jj++){
input[i/5] <<'\t' << i/100.0 << "\t" << x[i-1] << '\t' <<
density[i][jj-1] << endl;
}
}
}

for (int i=0;i<Nstepoutput;i++){
input[i].close();
}

return 0;
}

Jul 18 '06 #1
5 5253
lixiaoyao wrote:
hey all
I wrote the following code which run well in g++, but when I try to
compile it in C++ builder, it report a bunch of problems, the most
frustrating one is
"[C++ Error] Unit1.cpp(1): E2282 Namespace name expected"

I attached my code, anyone can help me run this code smoothly? I really
appreciate it.
I don't know about running it, it a bit of a mess, but it should compile
if you fix one gccism:
Thanks a lot
B
using namespace std;
#include <iostream>
#include <fstream>
#include <cmath>

int main(){
int Nstep=500;//must be even
int Nstepoutput=50;
ofstream input[Nstepoutput];
Nstepoutput should be const int, C++ doesn't (yet?) support VLAs.

--
Ian Collins.
Jul 18 '06 #2
Ian Collins wrote:
lixiaoyao wrote:
hey all
I wrote the following code which run well in g++, but when I try to
compile it in C++ builder, it report a bunch of problems, the most
frustrating one is
"[C++ Error] Unit1.cpp(1): E2282 Namespace name expected"

I attached my code, anyone can help me run this code smoothly? I really
appreciate it.

I don't know about running it, it a bit of a mess, but it should compile
if you fix one gccism:
And maybe adding "using namespace std;" at the beginning of the
program.
BTW, seems the g++ being used is rather old, as any recent g++ will
need it too.

Jul 18 '06 #3
jo******@gmail.com wrote:
Ian Collins wrote:
>>lixiaoyao wrote:
>> hey all
I wrote the following code which run well in g++, but when I try to
compile it in C++ builder, it report a bunch of problems, the most
frustrating one is
"[C++ Error] Unit1.cpp(1): E2282 Namespace name expected"

I attached my code, anyone can help me run this code smoothly? I really
appreciate it.

I don't know about running it, it a bit of a mess, but it should compile
if you fix one gccism:


And maybe adding "using namespace std;" at the beginning of the
program.
BTW, seems the g++ being used is rather old, as any recent g++ will
need it too.
The OP did, right at the top. I let that go this time...

--
Ian Collins.
Jul 18 '06 #4
lixiaoyao schrieb:
hey all
I wrote the following code which run well in g++, but when I try to
compile it in C++ builder, it report a bunch of problems, the most
frustrating one is
"[C++ Error] Unit1.cpp(1): E2282 Namespace name expected"

I attached my code, anyone can help me run this code smoothly? I really
appreciate it.
Thanks a lot
B
Put his line...
using namespace std;
#include <iostream>
#include <fstream>
#include <cmath>
....here.

I.e.:

#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
int main(){
[10m. lines deleted...]
}

Stefan
--
Stefan Naewe
naewe.s_AT_atlas_DOT_de
Jul 18 '06 #5
lixiaoyao wrote:
hey all
I wrote the following code which run well in g++, but when I try to
compile it in C++ builder, it report a bunch of problems, the most
frustrating one is
"[C++ Error] Unit1.cpp(1): E2282 Namespace name expected"

I attached my code, anyone can help me run this code smoothly? I really
appreciate it.
Thanks a lot
B
using namespace std;
At this point there is no namespace called std. You have to include
some standard library header (or otherwise define it). One of the
basic tenets of standard C and C++ is that your program is pretty
much an empty slate at the beginning of a translation unit. Until
you start including declarations they don't exist. There's nothing
special about std versus any other namespace other than it's reserved
for the standard library.
Jul 18 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Marcin Kalicinski | last post by:
Is the code below ill formed (because operator >> is defined in different namespace than class B)? It fails with VS 2005 Beta. I don't know if I should redesign my code or if I should find a...
7
by: Kevin Newman | last post by:
I've been toying with a namespace manager, and wanted to get some input. So what do you think? if (typeof com == 'undefined') var com = {}; if (!com.unFocus) com.unFocus = {}; ...
5
by: Alexis | last post by:
Hello, I have a set of classes I created from schema files using the xsd.exe tool. I'm using namespaces in the clases ( I had to because I have some classes with the same name but not the same...
0
by: richwangler | last post by:
This problem should be easily reproducable if anybody has the time. I need to build the following XML programatically and decided to use the XMLSerializer. I simplified the XML (myExample.xml)...
5
by: Mike Oliszewski | last post by:
Given the following c# code: namespace Company2 { public class SomeFunctions { public void FunctionA() { // Do Something. }
10
by: anders | last post by:
I have 2 external assemblies A1 and A2 that both define class X in the global namespace. I need to use both assemblies in my VB project but the names X are ambiguous. How can I get around this...
4
by: Kevin Newman | last post by:
The primary problem I've had with php is the lack of namespaces, which makes OOP very difficult to organize, since you end up with large number of classes cluttering up the same namespace - which...
30
by: Pep | last post by:
Is it best to include the code "using namespace std;" in the source or should each keyword in the std namespace be qualified by the namespace tag, such as std::cout << "using std namespace" <<...
3
by: George | last post by:
I am currently developing an xbrl validation software that takes an xml instance file and a lot of schemas(xsd files) and validates it against the xsd files. I am using Visual basic in visual...
7
by: Armin Zingler | last post by:
Hi all, I have a Form called "Main": Public Class Main Private Sub Button1_Click( _ ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button1.Click
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.