VC++ Help: convert from System::String to const char*;

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 3
Reputation: desimator55 is an unknown quantity at this point 
Solved Threads: 0
desimator55 desimator55 is offline Offline
Newbie Poster

VC++ Help: convert from System::String to const char*;

 
0
  #1
Oct 23rd, 2009
I'm using VC++ .net to write a program for searching through files in a directory and then opening them. The only problem I have run into is opening the file. I tried using streamreader but this does not work for opening pdf files. Currently I'm using system ("start //location and name of file");
ex:
  1. system("start c:\\Users\\Member\\Desktop\\filename.pdf");

Now this works great except for the fact that I need for filename to be changed while in my program. I tried passing a string that was gathered earlier in the program into it and I get an error saying that cannot convert parameter 1 from System:: String ^ to const char *
code error:
  1. system("start c:\\Users\\Member\\Desktop\\"+filename+".pdf");

Any and all help will be appreciated. ps: I have trolled the interwebz looking for an answer and can't find anything helpful.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 52
Reputation: Fbody is an unknown quantity at this point 
Solved Threads: 6
Fbody Fbody is offline Offline
Junior Poster in Training
 
0
  #2
Oct 23rd, 2009
Are you using the <string> header?

If so, have you tried using filename.c_str() to get the actual string characters rather than the array?
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 681
Reputation: Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of 
Solved Threads: 133
Tom Gunn's Avatar
Tom Gunn Tom Gunn is offline Offline
Practically a Master Poster
 
0
  #3
Oct 23rd, 2009
Are you using the <string> header?
System::String is not the same as std::string . The former is the .NET framework's string class that is used in C++/CLI code.

I have trolled the interwebz looking for an answer and can't find anything helpful.
Your question is a Microsoft knowledge base article. It came up as the first hit when searching Google for your thread title.
Last edited by Tom Gunn; Oct 23rd, 2009 at 1:18 pm.
-Tommy (For Great Justice!) Gunn
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 52
Reputation: Fbody is an unknown quantity at this point 
Solved Threads: 6
Fbody Fbody is offline Offline
Junior Poster in Training
 
0
  #4
Oct 23rd, 2009
Originally Posted by Tom Gunn View Post
System::String is not the same as std::string . The former is the .NET framework's string class that is used in C++/CLI code.
...
Oh...

As I'm sure you've guessed, I'm pretty new to C++ (especially VC++).

Thanks for the info.
Last edited by Fbody; Oct 23rd, 2009 at 1:24 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 3
Reputation: desimator55 is an unknown quantity at this point 
Solved Threads: 0
desimator55 desimator55 is offline Offline
Newbie Poster
 
0
  #5
Oct 23rd, 2009
Originally Posted by Tom Gunn View Post
System::String is not the same as std::string . The former is the .NET framework's string class that is used in C++/CLI code.


Your question is a Microsoft knowledge base article. It came up as the first hit when searching Google for your thread title.
I tried implementing those examples into my code but received varying errors from each. The main error was when trying to #include the header files that they supplied. Each method I fooled around with for an amount of time before I decided to ask here. I thought that the last method was my best hope because it states that it is available for Visual C++ 2008.
Last edited by desimator55; Oct 23rd, 2009 at 1:35 pm. Reason: Added information
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,648
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
-7
  #6
Oct 23rd, 2009
The last example can't be compled with the express edition.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 3
Reputation: desimator55 is an unknown quantity at this point 
Solved Threads: 0
desimator55 desimator55 is offline Offline
Newbie Poster
 
0
  #7
Oct 23rd, 2009
Originally Posted by Ancient Dragon View Post
The last example can't be compled with the express edition.
Oh, well then I guess I will have to get a complete version of Visual Studio 2008. So if and when I get this that code will work then? Are there any ways to work around this or do I have to locate the complete version? I have to leave for the weekend so thank you for the help and I'll check as soon as possible for an answer.
Last edited by desimator55; Oct 23rd, 2009 at 1:50 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,648
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
-7
  #8
Oct 23rd, 2009
I don't know of any workaround, but then I have not done all that much CLR programming.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 519 | Replies: 7
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC