[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1046
  • Last Modified:

convert from string to LPCSTR

how to convert from string to LPCSTR?
0
m-jansen
Asked:
m-jansen
  • 3
  • 2
2 Solutions
 
ikeworkCommented:
hi m-jansen,

CString s = "abc";
LPCSTR a = s;


LPCSTR CString::operator() const


hope it helps :)
ike
0
 
sathisemailCommented:
You can look at the following link which provides a set of string conversion functions which include string to LPCSTR conversion as well.

http://www.codeproject.com/string/tconvert.asp

And these two pages gives you details about the different types of string and their conversions as well..

http://www.codeproject.com/string/cppstringguide1.asp
http://www.codeproject.com/string/cppstringguide2.asp

regards
Sathis
0
 
m-jansenAuthor Commented:
what do I have to include to use CString?

CString s = "abc";
LPCSTR a = s;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
m-jansenAuthor Commented:
i have tried to #include <cstring> but that does not work
0
 
m-jansenAuthor Commented:
got it
#include "atlstr.h"
0
 
sathisemailCommented:
If you are working in an MFC then it is defined in afxstr.h will be included automatically by the class wizard itself.

But if it is not an MFC app, then its better to use 'std::string'

and to convert it to LPCSTR use the function .c_str()

regards
Sathis
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now