I have a program that uses getline() to read a line from a file.
It's doing this for an INI file reader. I'm trying to get the line
parser function to remove the comments from each line if there are some.
I've got this done using: std::string. I need to cast it from
std::string(basic string) to a CString(LPCTSTR). When I use String.c_str
function, it won't cast it to an LPCTSTR, i've also tried a nonconstant
version: LPSTR.
Any help would be appreciated! 7 2880
"Daniel Moree" <D_*****@Shadowbranch.com> wrote in message
news:s8****************@bignews6.bellsouth.net... I have a program that uses getline() to read a line from a file. It's doing this for an INI file reader. I'm trying to get the line parser function to remove the comments from each line if there are some. I've got this done using: std::string. I need to cast it from std::string(basic string) to a CString(LPCTSTR). When I use String.c_str function, it won't cast it to an LPCTSTR, i've also tried a nonconstant version: LPSTR.
Any help would be appreciated!
Step 1, get the size of the std::string string (length() will do);
Step 2, allocate enough memory for the LPCTSTR. If LPCTSTR is a macro to a
const something than allocate for the non-const version;
Step 3, invoke std::copy, now you are done.
Ben
On Fri, 16 Sep 2005 19:02:35 -0400, Daniel Moree wrote: I have a program that uses getline() to read a line from a file. It's doing this for an INI file reader. I'm trying to get the line parser function to remove the comments from each line if there are some. I've got this done using: std::string. I need to cast it from std::string(basic string) to a CString(LPCTSTR). When I use String.c_str function, it won't cast it to an LPCTSTR, i've also tried a nonconstant version: LPSTR.
Any help would be appreciated!
It's tricky to tell without seeing the actual error message (hint, hint),
but are you by chance doing a Unicode build? If so, you will have to
convert the string, since LPCSTSTR will point to wide characters.
- Jay
ok here's the error message:
c:\projects\codename_shadow\cconfig.cpp(46) : error C2664: 'fnError' :
cannot convert parameter 2 from 'const char *(void) const' to 'const char *'
There is no context in which this conversion is possible
here is the code:
bool CConfig::ParseLine(std::string Line){
size_t offset = Line.find("//");
if(offset != std::string::npos){
Line = Line.substr(0, offset);
}
if(Line.length == 0){ return(true); }
fnError(hwnd, Line.c_str);
return(true);
}
void fnError(HWND hWnd, LPCTSTR msg){
ShowCursor(true);
MessageBox(hWnd, msg, "Error!", MB_OK | MB_ICONSTOP);
ShowCursor(false);
}
Daniel Moree wrote: I have a program that uses getline() to read a line from a file. It's doing this for an INI file reader. I'm trying to get the line parser function to remove the comments from each line if there are some. I've got this done using: std::string. I need to cast it from std::string(basic string) to a CString(LPCTSTR). When I use String.c_str function, it won't cast it to an LPCTSTR, i've also tried a nonconstant version: LPSTR.
Any help would be appreciated!
On Fri, 16 Sep 2005 20:00:03 -0400, Daniel Moree wrote: ok here's the error message: c:\projects\codename_shadow\cconfig.cpp(46) : error C2664: 'fnError' : cannot convert parameter 2 from 'const char *(void) const' to 'const char *' There is no context in which this conversion is possible
here is the code: bool CConfig::ParseLine(std::string Line){ size_t offset = Line.find("//"); if(offset != std::string::npos){ Line = Line.substr(0, offset); } if(Line.length == 0){ return(true); } fnError(hwnd, Line.c_str);
c_str is a function.
fnError(hwnd, Line.c_str());
- Jay
Daniel Moree wrote: ok here's the error message: c:\projects\codename_shadow\cconfig.cpp(46) : error C2664: 'fnError' : cannot convert parameter 2 from 'const char *(void) const' to 'const char *' There is no context in which this conversion is possible
here is the code: bool CConfig::ParseLine(std::string Line){ size_t offset = Line.find("//"); if(offset != std::string::npos){ Line = Line.substr(0, offset); } if(Line.length == 0){ return(true); } fnError(hwnd, Line.c_str);
Maybe:
fnError( hwnd, Line.c_str() ); return(true); }
void fnError(HWND hWnd, LPCTSTR msg){ ShowCursor(true); MessageBox(hWnd, msg, "Error!", MB_OK | MB_ICONSTOP); ShowCursor(false); }
Best
Kai-Uwe Bux
ok fixed, kept missing that c_str() function thing. Sometimes it helps
to have someone else look at the code.
Thanks again for everyones help!
Kai-Uwe Bux wrote: Daniel Moree wrote:
ok here's the error message: c:\projects\codename_shadow\cconfig.cpp(46) : error C2664: 'fnError' : cannot convert parameter 2 from 'const char *(void) const' to 'const char *' There is no context in which this conversion is possible
here is the code: bool CConfig::ParseLine(std::string Line){ size_t offset = Line.find("//"); if(offset != std::string::npos){ Line = Line.substr(0, offset); } if(Line.length == 0){ return(true); } fnError(hwnd, Line.c_str);
Maybe:
fnError( hwnd, Line.c_str() );
return(true); }
void fnError(HWND hWnd, LPCTSTR msg){ ShowCursor(true); MessageBox(hWnd, msg, "Error!", MB_OK | MB_ICONSTOP); ShowCursor(false); } Best
Kai-Uwe Bux
Daniel Moree wrote: ok fixed, kept missing that c_str() function thing. Sometimes it helps to have someone else look at the code.
Now that you understand the problem, look again at the error message. It
really does point you there, but you have to know how to read it.
--
Pete Becker
Dinkumware, Ltd. ( http://www.dinkumware.com) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Michael R. Copeland |
last post by:
How do I cast or promote a char variable to a char* variable? For
example, I want to use strcat to append a character to an existing
"string". (BTW, I'm not able to use STL string or CString data...
|
by: Dennis Myrén |
last post by:
Hi.
Is there a way to make sure that float, double and decimal data types
never will be presented in a scientific notation?
I have tried to round(Math.Round) float's to 7 decimals, double's to...
|
by: AC |
last post by:
I've put some strings into a stack, and now I want to convert the stack to an string based array. Here's what I'm trying to do (this returns a cast error)
string results =...
|
by: Barry Mossman |
last post by:
Hi,
I get the feeling that I am missing something with regards to casting.
The CopyTo method allows me to copy the contents of a collection into an
array. My collection is a MatchCollection...
|
by: Brian |
last post by:
Hello!
What is the proper syntax for casting? For example, how do I change an
Integer in to a String if the variable is called Joe1 and has 20 assigned to
it.
Thanks,
Brian
|
by: black(flashing vampire) |
last post by:
hi all~
i'm newbie to C++ string type and get confused when trying to convert
an int into string, i just want my cute messagebox to popup mouse
positions, here is my code:
MessageBox(NULL,...
|
by: |
last post by:
I'm querying Index Server to return search results, both regular properties
and some custom properties I've created. Index Server has this preference
for thinking about information as strings...
|
by: Ajeet |
last post by:
hi
I am having some difficulty in casting using generics. These are the
classes.
public interface IProvider<PROF>
where PROF : IProviderProfile
{
//Some properties/methods
}
|
by: Ken Fine |
last post by:
This is a basic question. What is the difference between casting and using
the Convert.ToXXX methods, from the standpoint of the compiler, in terms of
performance, and in other ways? e.g.
...
|
by: guncrew |
last post by:
Hello I am starting to use Python.
I found a nice little example for subsituting and splitting texts and counting words separated by defined expressions (in the example , and blanks). Unfotunately...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |