Escape Sequence

Oct 5, 2011 at 8:25am
Hi Guys

I was wondering if someone could be kind enough to tell me how I can stop VC++ from recognising the escape sequence i.e."\".

Im trying to reference a folder in my code by stating the full file path but I get an error message when I type in the following

 
String^ cn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Documents" and Settings\'" 


Any ideas?

Thanks
Last edited on Oct 5, 2011 at 8:25am
Oct 5, 2011 at 8:29am
I have no idea what a String^ is and what the @ does, but why do you have quotations inside your folder name? The colouring alone should notify you that part of it isn't part of the string literal any longer.

Also, use the '/' character for directories. That should work.
Oct 5, 2011 at 8:30am
I was wondering if someone could be kind enough to tell me how I can stop VC++ from recognising the escape sequence i.e."\".


Looks like you're actually coding in some kind of .NET language. That said, either use two such slashes, or just use the other slash.

String^ cn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\\Documents and Settings\\'"

or

String^ cn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:/Documents and Settings/'"




Last edited on Oct 5, 2011 at 8:31am
Oct 5, 2011 at 8:44am
Many thanks guys... its works perfect now.

im getting used to programming in c++ - im naturally a VB & c# programmer.

Thanks again!
Oct 5, 2011 at 8:50am
closed account (1vRz3TCk)
I don't believe that C++/CLI supports verbatim sting literals [@] so you would have to drop that.

Edit:
... but I get an error message when ...
in the future it would be good to include the error messages that you get.
Last edited on Oct 5, 2011 at 8:53am
Oct 5, 2011 at 8:51am
Hi gaminic - just to follow on from your post, you said you dont know what a String^ is, but in Visual C++ i presumed this was the only way to declare a string variable i.e.

 
String^ variable = "This is a string variable";


Im presuming this isnt the best way or default way to declare a string variable? What should I do instead?

Thanks
Oct 5, 2011 at 8:55am
string variable = "This is a string variable";?

You do have to include the <string> header though.
Oct 5, 2011 at 8:58am
ok great - many thanks for your help.
Oct 5, 2011 at 9:06am
closed account (1vRz3TCk)
shamas21 wrote:
but in Visual C++ i presumed this was the only way to declare a string variable
Visual C++ is not a language, it is an IDE. You can do C++ and C++/CLI projects, they are different languages, String^ variable = "This is a string variable"; is C++/CLI not C++. You can mix C++ in a C++/CLI project but it is not wise unless you know what you are doing.
Oct 5, 2011 at 12:11pm
The reason why I use Visual C++ is because it comes with a Forms based environment i.e. C++/CLI.

So I can design and use buttons, textboxes, treeviews, listviews etc... in Visual C++ and still use the power of C++.

But unless im mistaken, I cant do this in other IDEs? I mean most of the application I have built in the past using VB and C# are Forms based projects, I mean how else can I get the user to interact with a program unless it Forms based? My understanding of the C++ is that not all IDEs provide Forms and that its not an easy task to build a Forms based project unless I use Visual C++?

Thanks
Oct 5, 2011 at 12:53pm
I mean how else can I get the user to interact with a program unless it Forms based?


Presumably you mean buttons and textboxes and all that sort of thing, rather than just plain interaction.

You could just write the whole thing yourself. This would be a lot of work, though, and most people go with what are generally known as widget toolkits:

http://en.wikipedia.org/wiki/Widget_toolkit

There are lots. Lots and lots and lots.
http://en.wikipedia.org/wiki/List_of_widget_toolkits


Last edited on Oct 5, 2011 at 12:53pm
Oct 5, 2011 at 12:59pm
Oh I see. So I can create GUI interface through wiedgets. I didnt know I could do this. I presume the widgets are use with native C++, which I guess is better for me as I can learn the proper C++ programming language.

Thanks
Oct 5, 2011 at 1:02pm
closed account (1vRz3TCk)
The Forms based projects in VC use a language design to 'extend' C++, it is called C++/CLI.

While it is possible to mix C++ with C++/CLI it is more of a pain than than a help. You will be constantly converting between managed and unmanaged types, probably forgetting what memory needs releasing an what doesn't, and so on.

If you want to learn C++ stay way from Forms based projects, look at something like wxWidgets or plain Windows API.

If you want to do Forms based projects, stick with C#.


Edit:
Sorry, but the blurring of C++ and C++/CLI by Microsoft is a bit of a bugbear of mine. Far to many beginners get mislead by this.
Last edited on Oct 5, 2011 at 1:12pm
Oct 5, 2011 at 2:58pm
Ok great. Thanks for the help.

Edit--

Sorry just more thing. So I can create native C++ program in Visual C++ right? So then shall I create my Forms based programs using an ALT program in VC++? and then use the wxWidgets?

Sorry to be a pain
Last edited on Oct 5, 2011 at 3:01pm
Topic archived. No new replies allowed.