Newbie Question

  • Thread starter Anil Gupte/iCinema.com
  • Start date
A

Anil Gupte/iCinema.com

I am very new to C++ (Actually have dabbled in it before but nevermind).
This is my first appliccation that I started from scratch. I created a
Console Application in VC 2005 and this is what I have so far:
using namespace System;

using namespace System::IO;

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])

{

DirectoryInfo* di = new DirectoryInfo(".");

String* files[] = Directory::GetFiles(di->ToString()];

return 0;

}

When I compile I get lots of errors. Even if I comment out the String*
files line I get at least three errors. Here they are:

Error 1 error C2065: 'DirectoryInfo' : undeclared identifier
Error 2 error C2065: 'di' : undeclared identifier
Error 3 error C2061: syntax error : identifier 'DirectoryInfo'
Error 4 error C2065: 'String' : undeclared identifier
Error 5 error C2065: 'files' : undeclared identifier
Error 6 error C2059: syntax error : ']'
Error 7 error C2653: 'Directory' : is not a class or namespace name


Any help appreciated. Thanx in advance.
 
G

Giovanni Dicanio

This is my first appliccation that I started from scratch. I created a
Console Application in VC 2005 and this is what I have so far: [...]
When I compile I get lots of errors.

This code compiles fine for me:

<code>

#include "stdafx.h"

using namespace System;
using namespace System::IO;

int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");

DirectoryInfo ^ di = gcnew DirectoryInfo(".");
array< String^ >^ files = Directory::GetFiles( di->ToString() );

return 0;
}

</code>

Note that to use the .NET Framework classes from C++, you should use C++/CLI
extensions of the C++ language.
In this case, instead of native pointers (*), you should have managed
references (^), instead of 'new' you should use 'gcnew', etc.

Giovanni
 
A

Anil Gupte/iCinema.com

Ok that was completely Italian to me. Just joking, no offence. :)

Anyway, I copy-pasted your code and still gives me lots of errors.
Error 1 error C2065: 'array' : undeclared identifier
Error 2 error C2653: 'System' : is not a class or namespace name
Error 3 error C2065: 'String' : undeclared identifier
Error 4 error C2059: syntax error : '>'
Error 5 error C2143: syntax error : missing ';' before '{'
Error 6 error C2447: '{' : missing function header (old-style formal list?)

But where can I read more about use CLI extensions and managed references?

Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com
www.wizo.tv
Giovanni Dicanio said:
This is my first appliccation that I started from scratch. I created a
Console Application in VC 2005 and this is what I have so far: [...]
When I compile I get lots of errors.

This code compiles fine for me:

<code>

#include "stdafx.h"

using namespace System;
using namespace System::IO;

int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");

DirectoryInfo ^ di = gcnew DirectoryInfo(".");
array< String^ >^ files = Directory::GetFiles( di->ToString() );

return 0;
}

</code>

Note that to use the .NET Framework classes from C++, you should use
C++/CLI extensions of the C++ language.
In this case, instead of native pointers (*), you should have managed
references (^), instead of 'new' you should use 'gcnew', etc.

Giovanni
 
G

Giovanni Dicanio

I copy-pasted your code and still gives me lots of errors.
Error 1 error C2065: 'array' : undeclared identifier
Error 2 error C2653: 'System' : is not a class or namespace name
Error 3 error C2065: 'String' : undeclared identifier
Error 4 error C2059: syntax error : '>'
Error 5 error C2143: syntax error : missing ';' before '{'
Error 6 error C2447: '{' : missing function header (old-style formal
list?)

You can start creating a new C++/CLI project with Visual Studio 2008 using
this sequence:

New Project | Visual C++ | CLR | CLR Console Application

And you can copy-and-paste the code I posted there.

(Before posting that code, I built it on my VS2008 IDE.)
But where can I read more about use CLI extensions and managed references?

Nish wrote a book about that topic:

http://www.amazon.com/CLI-Action-Manning-Nishant-Sivakumar/dp/1932394818

He masters the C++/CLI extensions, and I think that you can find interesting
information on his blogs and his CodeProject articles, too.

I hope that my "Italglish" is clear enough... ;)

Giovanni
 
A

Anil Gupte/iCinema.com

Thanx! Your english is very clear. I had trouble understanding the
technical stuff. Thanx for your help, I will do some reading on this.
 
D

David Wilkinson

Anil said:
I am very new to C++ (Actually have dabbled in it before but nevermind).
This is my first appliccation that I started from scratch. I created a
Console Application in VC 2005 and this is what I have so far:
using namespace System;

using namespace System::IO;

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])

{

DirectoryInfo* di = new DirectoryInfo(".");

String* files[] = Directory::GetFiles(di->ToString()];

return 0;

}

When I compile I get lots of errors. Even if I comment out the String*
files line I get at least three errors. Here they are:

Error 1 error C2065: 'DirectoryInfo' : undeclared identifier
Error 2 error C2065: 'di' : undeclared identifier
Error 3 error C2061: syntax error : identifier 'DirectoryInfo'
Error 4 error C2065: 'String' : undeclared identifier
Error 5 error C2065: 'files' : undeclared identifier
Error 6 error C2059: syntax error : ']'
Error 7 error C2653: 'Directory' : is not a class or namespace name


Any help appreciated. Thanx in advance.

Anil:

#include "stdafx.h" must be the first line in the file. Everything before it is
ignored. This is the cause of your "undeclared identifier" errors.

In addition, you seem not to be aware that in order to write managed (.net) code
in VS2005 and beyond you should use the new C++/CLI language.

You might be wise to focus initially on standard C++, or consider C# instead.

C++ is essentially a combination of the capabilities of standard C++ and C# in
one rather complex language.
 
D

David Wilkinson

David said:
Anil said:
I am very new to C++ (Actually have dabbled in it before but
nevermind). This is my first appliccation that I started from scratch.
I created a Console Application in VC 2005 and this is what I have so
far:
using namespace System;

using namespace System::IO;

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])

{

DirectoryInfo* di = new DirectoryInfo(".");

String* files[] = Directory::GetFiles(di->ToString()];

return 0;

}

When I compile I get lots of errors. Even if I comment out the
String* files line I get at least three errors. Here they are:

Error 1 error C2065: 'DirectoryInfo' : undeclared identifier
Error 2 error C2065: 'di' : undeclared identifier
Error 3 error C2061: syntax error : identifier 'DirectoryInfo'
Error 4 error C2065: 'String' : undeclared identifier
Error 5 error C2065: 'files' : undeclared identifier
Error 6 error C2059: syntax error : ']'
Error 7 error C2653: 'Directory' : is not a class or namespace name


Any help appreciated. Thanx in advance.

Anil:

#include "stdafx.h" must be the first line in the file. Everything
before it is ignored. This is the cause of your "undeclared identifier"
errors.

In addition, you seem not to be aware that in order to write managed
(.net) code in VS2005 and beyond you should use the new C++/CLI language.

You might be wise to focus initially on standard C++, or consider C#
instead.

C++ is essentially a combination of the capabilities of standard C++ and
C# in one rather complex language.

Oops, I meant:

C++/CLI is essentially a combination of the capabilities of standard C++ and C#
in one rather complex language.
 
P

Pavel A.

Anil Gupte/iCinema.com said:
I am very new to C++ (Actually have dabbled in it before but nevermind).
This is my first appliccation that I started from scratch.

That's already wrong. Being very new in something, you start from samples,
not from scratch. And there's lots of samples in the VS and MSDN site.

--PA
 
A

Anil Gupte/iCinema.com

Yeah, I have done stuff with samples and tuorials, but this was my first try
at doing a blank sheet. Maybe I will revert to using an example as a
template.

Thanx,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top