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;
} 5 5261
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.
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. 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.
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 better compiler?
namespace N1
{
class A { };
std::istream &operator >>(std::istream &, A &);
|
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 = {};
com.unFocus.Namespaces = new function() {
this.register = function(namespace) {
namespace = namespace.split('.');
|
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 class )
Here is how a given class wil looks like.
<System.Xml.Serialization.XmlRootAttribute(:="mynamespace",
IsNullable:=False)> _
Public Class...
|
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) that i need to
create for this post.
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"...
|
by: Mike Oliszewski |
last post by:
Given the following c# code:
namespace Company2
{
public class SomeFunctions
{
public void FunctionA()
{
// Do Something.
}
| |
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 problem?
Is there a way to refer to the assembly, f.ex. A1.X and A2.X (this syntax
does not compile).
Or can I change the name X in the Imports...
|
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 leads to a secondary
problem involving php's __autoload feature. Since you cannot specify a
namespace when calling a class that may not have been...
|
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" << std::endl;
Myself I am not sure which I prefer, it is certainly easier to specify that
the std namespace is being used instead of tagging each...
|
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 studio 2005. I have managed to
cycle through the xml file , validate most of the variables, however, i have
some problems with the namespaces of some...
|
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
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |