LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-05-2008, 02:41 PM   #16
jonwatson
Member
 
Registered: Jun 2004
Location: Nova Scotia, Canada!
Distribution: Ubuntu
Posts: 170

Rep: Reputation: 30

Quote:
Originally Posted by Nylex View Post
c_str() returns a constant C-string. I suppose you could use strcpy() or strncpy() (cstring header) to do what you want.

Hmmm...OK, I'll try something else. I would have thought that it wouldn't matter if it returns a const until I try to change it, which I am not.

Jon
 
Old 06-05-2008, 02:45 PM   #17
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
c_str() returns a const pointer, so even though you aren't trying to modify it, storing it in a non-const variable leaves open the possibility of modification. At least that's what I think is happening.
 
Old 06-05-2008, 02:53 PM   #18
jonwatson
Member
 
Registered: Jun 2004
Location: Nova Scotia, Canada!
Distribution: Ubuntu
Posts: 170

Rep: Reputation: 30
Yup, that was it. I did try to change p to const char* but it still threw an error. What I didn't notice is that is was the same error, but on a different line after the change. The second error was in reference to me passing the const char* to a function that I wrote that only have char* as an input argument. So, it appeared that I was getting the same error regardless. However, changing the function argument to const char* fixed it all up.

Thanks
 
Old 06-05-2008, 03:10 PM   #19
swodniw
Member
 
Registered: Jan 2006
Posts: 35

Rep: Reputation: 16
I am sure this is a typo but
Quote:
c_str() returns a const pointer,
c_str returns a pointer to constant char, not a constant pointer to char.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Telling people to use "Google," to "RTFM," or "Use the search feature" Ausar General 77 03-21-2010 11:26 AM
bash cripting function to "identify" any char in a string? minike Programming 8 02-01-2006 09:45 AM
using java to find the location of the "\" char in a string caged Programming 8 02-03-2004 10:42 AM
<input type="button" disabled="true" > does not work in ns4.7 or 4.9 cybercop12us Programming 2 11-29-2002 08:31 AM
Cannot convert string "%s" to type %s jamaso Slackware 1 05-05-2002 04:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration