Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 23rd, 2012  |  syntax: None  |  size: 0.74 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. in c  , if I pass a CString to a function by reference and assign it to another CString it is truncated
  2. void SomeFunction(CString& paramstring) //let's pretend we pass a string with the value "hello"
  3. {
  4.      int size=paramstring.GetLength(); //size now contains an incorrect shorter value like 4
  5.      CString localstring=paramstring;//localstring contains something like "hell" or "hel"
  6. }
  7.        
  8. #include <iostream>
  9. #include <afx.h>
  10. using namespace std;
  11.  
  12. //let's pretend we pass a string with the value "hello"
  13. void fun(CString& paramstring)
  14. {
  15.     int size=paramstring.GetLength();  
  16.     cout<<"size= "<<size<<"n";
  17.     CString localstring=paramstring;
  18.     wcout<<"string = "<<(LPCTSTR)localstring<<"n";
  19. }
  20.  
  21. int main()
  22. {
  23.     CString s ("Hello");
  24.     fun(s);
  25. }