Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » problem with fprintf
problem with fprintf [message #29217] Mon, 11 October 2010 14:08 Go to next message
o_wild is currently offline  o_wild
Messages: 28
Registered: December 2008
Location: Urmqi
Promising Member
The following code is excerpt of an opensource software, but there is error when compiled.

fprintf(ofp,"%s\n",mes1); // mes1 is of type String

The error message is
cannot pass objects of non-trivially-copyable type 'class Upp::String' through '...'

The software can be compiled with both mingw and MSVC as the developer says. Since I have problem using MSVC due to C2001 error(new line in constant), I choose MingGW 4.5.0.

Is their any substitute for 'fprintf'? by the way, i tested 'printf' and found the same problem.
Re: problem with fprintf [message #29218 is a reply to message #29217] Mon, 11 October 2010 14:26 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
The problem is that when trying to pass your string as an argument ta a variable argument function the compiler has no means of knowing that you are trying to pass a C string. In such cases you must explicitly specify that you want to convert from String to C string. Try ~mes1, mes1.Begin() or casting to (char*).
Re: problem with fprintf [message #29256 is a reply to message #29218] Wed, 13 October 2010 12:54 Go to previous messageGo to next message
o_wild is currently offline  o_wild
Messages: 28
Registered: December 2008
Location: Urmqi
Promising Member
Thanks. Both will do.
Re: problem with fprintf [message #29332 is a reply to message #29217] Fri, 15 October 2010 14:44 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
o_wild wrote on Mon, 11 October 2010 08:08

The following code is excerpt of an opensource software, but there is error when compiled.

fprintf(ofp,"%s\n",mes1); // mes1 is of type String

Is their any substitute for 'fprintf'? by the way, i tested 'printf' and found the same problem.


Yes, Format. It is typesafe - you would not encounter above kind of problem there.

So in "true" U++ the code would look like this:

FileOut ofp;
....
ofp.Put(Format("%d\n", mes1);
Previous Topic: Error in HomeBudget Example?
Next Topic: HttpClient Execute vs ExecuteRedirect
Goto Forum:
  


Current Time: Thu Mar 28 23:39:35 CET 2024

Total time taken to generate the page: 0.01339 seconds