Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
C++
CString WriteString;
....

	WriteString.Format("%s.%d d",WriteString,NI);


At above WriteStringthe buffer too small warning is shown when executed any times because CStringtype is not enough to hold string of any size.

My goal is to get content ofWriteStringto write in to a file at end.

But it shows the warning when size of WriteStringreach to a limit. Is there any other way to write these strings to a file?or make the writeString be of unlimited size.
Posted
Comments
swapnilKumbhar 2-Apr-12 1:31am    
Refer this.may help you to solve your query.
http://msdn.microsoft.com/ja-jp/library/ms928943.aspx
Resmi Anna 2-Apr-12 1:53am    
How much data is the WriteString holds. Actually there is no size limit for CString. Depends on system memory and process memory. Please post the exact warning message and line you are getting.
chaiein 2-Apr-12 4:31am    
solved problem as below solutions :) thank you :)

C++
WriteString.AppendFormat("%du.",NI,CPianoCtrl::NoteUporDwn);


This also works.
 
Share this answer
 
In the Format(..) context,
try to use the string as the receiver only :) :
C++
CString cszComposed(_T("SomeValue"));
...
CString cszTemp;
cszTemp.Format(_T(".%d d"), NI);
cszComposed += cszTemp;
 
Share this answer
 
v2
Comments
chaiein 2-Apr-12 4:27am    
Thank you it works:)I have updated below solution 2 which can also works.
If your objective is to reuse variables, here goes the way to go:

CString WriteString;
....
 
	WriteString.Format("%s.%d d", CString(WriteString),NI);


Notice the CString() constructor call. You will have not problems because your format receives a copy of WriteString, instead of manipulating it directly.
 
Share this answer
 
Comments
Richard Deeming 10-Jul-15 13:47pm    
Do you really think the OP is still looking for a solution to a solved question from over three years ago?!
Member 5688443 10-Jul-15 14:04pm    
No, but other people can like my solution. He/She has not the exclusive right to the use of Internet.
Richard Deeming 10-Jul-15 14:07pm    
Posting new answers to old, solved questions is a form of abuse - you're not trying to help the OP, you're just trying to increase your reputation points.
Member 5688443 10-Jul-15 19:55pm    
Do you think I care that much about my reputation here? This is the first time I went to see it. Almost all points I got were from Sign Ins, that most likely are done automatically by the browser.
srilekhamenon 9-Aug-17 5:49am    
Thanks helped me :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900