Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » Invalid conversion 
	
		
		
			| Invalid conversion [message #7577] | 
			Sun, 07 January 2007 13:38   | 
		 
		
			
				
				
				
					
						  
						Gatling_Gun
						 Messages: 13 Registered: January 2007 
						
					 | 
					Promising Member  | 
					 | 
		 
		 
	 | 
 
	
		Help me with this code... 
 
char[10] = text1.GetText().ToString(); 
 
Ok char to string is an invalid conversion but I try c_str() but don't recognize it! 
 
Please help me!    
		
		
		[Updated on: Sun, 07 January 2007 13:39] Report message to a moderator  
 |  
	| 
		
	 | 
 
 
 |  
	| 
		
 |  
	| 
		
 |  
	| 
		
 |  
	| 
		
 |  
	
		
		
			| Re: Invalid conversion [message #7584 is a reply to message #7583] | 
			Sun, 07 January 2007 18:36   | 
		 
		
			
				
				
				  | 
					
						  
						mirek
						 Messages: 14271 Registered: November 2005 
						
					 | 
					Ultimate Member  | 
					 | 
		 
		 
	 | 
 
	
		
String text = ....
const char *s = text;
  
 
(warning: s valid only till next mutating operation on text). 
 
If you really need char[], you can also do this: 
 
char h[...];
strcpy(h, text);
  
 
Anyway, beware, there is a danger of buffer overrun (if text.GetLength() is greater than sizeof(h) - 1.) 
 
Alternative, without buffer overrun danger: 
 
Buffer<char> h(text.GetLength() + 1);
memcpy(h, text, text.GetLength() + 1);
  
		
		
		[Updated on: Sun, 07 January 2007 18:37] Report message to a moderator  
 |  
	| 
		
	 | 
 
 
 |   
Goto Forum:
 
 Current Time: Tue Nov 04 15:31:58 CET 2025 
 Total time taken to generate the page: 0.06324 seconds 
 |