944,144 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2757
  • C++ RSS
Oct 23rd, 2009
0

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

Expand Post »
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:
C++ Syntax (Toggle Plain Text)
  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:
C++ Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
desimator55 is offline Offline
3 posts
since Oct 2009
Oct 23rd, 2009
0
Re: VC++ Help: convert from System::String to const char*;
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?
Featured Poster
Reputation Points: 833
Solved Threads: 392
Posting Maven
Fbody is offline Offline
2,846 posts
since Oct 2009
Oct 23rd, 2009
0
Re: VC++ Help: convert from System::String to const char*;
Quote ...
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.

Quote ...
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.
Reputation Points: 1446
Solved Threads: 135
Practically a Master Poster
Tom Gunn is offline Offline
681 posts
since Jun 2009
Oct 23rd, 2009
0
Re: VC++ Help: convert from System::String to const char*;
Click to Expand / Collapse  Quote originally posted by Tom Gunn ...
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.
Featured Poster
Reputation Points: 833
Solved Threads: 392
Posting Maven
Fbody is offline Offline
2,846 posts
since Oct 2009
Oct 23rd, 2009
0
Re: VC++ Help: convert from System::String to const char*;
Click to Expand / Collapse  Quote originally posted by Tom Gunn ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
desimator55 is offline Offline
3 posts
since Oct 2009
Oct 23rd, 2009
-7
Re: VC++ Help: convert from System::String to const char*;
The last example can't be compled with the express edition.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005
Oct 23rd, 2009
0
Re: VC++ Help: convert from System::String to const char*;
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
desimator55 is offline Offline
3 posts
since Oct 2009
Oct 23rd, 2009
-7
Re: VC++ Help: convert from System::String to const char*;
I don't know of any workaround, but then I have not done all that much CLR programming.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: booking a ticket for flight
Next Thread in C++ Forum Timeline: Need help!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC