
Untitled
By: a guest on
May 23rd, 2012 | syntax:
None | size: 0.74 KB | hits: 10 | expires: Never
in c , if I pass a CString to a function by reference and assign it to another CString it is truncated
void SomeFunction(CString& paramstring) //let's pretend we pass a string with the value "hello"
{
int size=paramstring.GetLength(); //size now contains an incorrect shorter value like 4
CString localstring=paramstring;//localstring contains something like "hell" or "hel"
}
#include <iostream>
#include <afx.h>
using namespace std;
//let's pretend we pass a string with the value "hello"
void fun(CString& paramstring)
{
int size=paramstring.GetLength();
cout<<"size= "<<size<<"n";
CString localstring=paramstring;
wcout<<"string = "<<(LPCTSTR)localstring<<"n";
}
int main()
{
CString s ("Hello");
fun(s);
}