473,473 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

c++ code works in gcc2.9 not in gcc3.2.2

Hi,

Hope someone can help. I have the following c++ program which compiles
fine in gcc2.96, but won't compile in gcc3.2.2:

//FMain.cpp

#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>

int main()
{
int RunCurr = 66;
char* before = { "data/geom." };
char* after = { ".xml" };

std::ostringstream GeomFileName;

GeomFileName << before << setw(6)
<< setfill (48) << dec << RunCurr << after << ends ;

cout << GeomFileName.str() << endl;

return 0;
}

Any help is appreciated.

Regards,

Philip
Jul 22 '05 #1
5 1536
Philip Goisman wrote:
Hi,

Hope someone can help. I have the following c++ program which compiles
fine in gcc2.96, but won't compile in gcc3.2.2:
What errors did it give?

//FMain.cpp

#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>

int main()
{
int RunCurr = 66;
char* before = { "data/geom." };
char* after = { ".xml" };

std::ostringstream GeomFileName;

GeomFileName << before << setw(6)
<< setfill (48) << dec << RunCurr << after << ends ;
It's called std::ends, and you shouldn't be using it.

cout << GeomFileName.str() << endl;
std::cout and std::endl.

return 0;
}

Any help is appreciated.

Regards,

Philip


-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #2

"Philip Goisman" <go*****@physics.arizona.edu> wrote in message
news:66**************************@posting.google.c om...
Hi,

Hope someone can help. I have the following c++ program which compiles fine in gcc2.96, but won't compile in gcc3.2.2:

//FMain.cpp

#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>

int main()
{
int RunCurr = 66;
char* before = { "data/geom." };
char* after = { ".xml" };

std::ostringstream GeomFileName;

GeomFileName << before << setw(6)
<< setfill (48) << dec << RunCurr << after << ends ;
cout << GeomFileName.str() << endl;

return 0;
}

There are two problems:

1. The i/o manipulators are in namespace std.
2. GCC 3.2 is finding setfill(48) ambiguous. I tried your code on
several modern compilers, and only como 4.3.3 failed to complain of
this ambiguity. Off the top of my head, I'm not sure whose right.

Anyway, the following compiles on GCC 3.2:

int main()
{
int RunCurr = 66;
char* before = { "data/geom." };
char* after = { ".xml" };

std::ostringstream GeomFileName;

GeomFileName << before << std::setw(6)
<< std::setfill((char) 48)
<< std::dec << RunCurr << after << std::ends ;

std::cout << GeomFileName.str() << std::endl;

return 0;
}

You could also use something like this, which is easier to read.

const char zero = 48;
GeomFileName << before << std::setw(6)
<< std::setfill(zero)
<< std::dec << RunCurr << after << std::ends ;

HTH

Jonathan


Jul 22 '05 #3
"Jonathan Turkanis" <te******@kangaroologic.com> wrote in message
news:bu************@ID-216073.news.uni-berlin.de...
There are two problems:

1. The i/o manipulators are in namespace std.
Also 'cout' is in std.
this ambiguity. Off the top of my head, I'm not sure whose right.


I'm also not sure who's right. :-)

Jonathan
Jul 22 '05 #4
Jonathan Turkanis wrote:
"Philip Goisman" <go*****@physics.arizona.edu> wrote in message
news:66**************************@posting.google.c om...
Hi,

Hope someone can help. I have the following c++ program which


compiles
fine in gcc2.96, but won't compile in gcc3.2.2:

//FMain.cpp

#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>

int main()
{
int RunCurr = 66;
char* before = { "data/geom." };
char* after = { ".xml" };

std::ostringstream GeomFileName;

GeomFileName << before << setw(6)
<< setfill (48) << dec << RunCurr << after << ends


;
cout << GeomFileName.str() << endl;

return 0;
}


There are two problems:

1. The i/o manipulators are in namespace std.
2. GCC 3.2 is finding setfill(48) ambiguous. I tried your code on
several modern compilers, and only como 4.3.3 failed to complain of
this ambiguity. Off the top of my head, I'm not sure whose right.

Anyway, the following compiles on GCC 3.2:

int main()
{
int RunCurr = 66;
char* before = { "data/geom." };
char* after = { ".xml" };

std::ostringstream GeomFileName;

GeomFileName << before << std::setw(6)
<< std::setfill((char) 48)
<< std::dec << RunCurr << after << std::ends ;

std::cout << GeomFileName.str() << std::endl;

return 0;
}

You could also use something like this, which is easier to read.

const char zero = 48;
GeomFileName << before << std::setw(6)
<< std::setfill(zero)
<< std::dec << RunCurr << after << std::ends ;

even better would be:

GeomFileName << before << std::setw(6)
<< std::setfill('0')
<< std::dec << RunCurr << after << std::ends;

That way you don't have the implicit reliance on ASCII encoding of
character values.
Jul 22 '05 #5

"red floyd" <no*****@here.dude> wrote in message
news:iX*****************@newssvr29.news.prodigy.co m...
Jonathan Turkanis wrote:
"Philip Goisman" <go*****@physics.arizona.edu> wrote in message
You could also use something like this, which is easier to read.

const char zero = 48;
GeomFileName << before << std::setw(6)
<< std::setfill(zero)
<< std::dec << RunCurr << after << std::ends ; even better would be:

GeomFileName << before << std::setw(6)
<< std::setfill('0')
<< std::dec << RunCurr << after <<

std::ends;
That way you don't have the implicit reliance on ASCII encoding of
character values.


Certainly, if that's what the OP wants. He went to the trouble of
specifying 48, though, so I'm assuming he had some good reason.

Jonathan
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
2
by: Hendrik Schober | last post by:
Hi, the following is a boiled-down version of a problem we're plagued with. It's still a rather complicated class hierarchy, but if we remove one more item, the problem disappears. This is the...
3
by: Todd Nathan | last post by:
Have ported Until 2.5.2 which is a highly portable embedded FORTH-like language system to BeOS. Turned on -Wall cause I'm anal about cleaning up ports if I'm doing them, and have all but ONE...
8
by: G Patel | last post by:
I wrote the following program to remove C89 type comments from stdin and send it to stdout (as per exercise in K&R2) and it works but I was hoping more experienced programmer would critique the...
6
by: Paolo Pignatelli | last post by:
I have an aspx code behind page that goes something like this in the HTML view: <asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%#"mailto:" &amp;...
2
by: Enrique Bustamante | last post by:
Casting arrays that works on watch and command window but not in code. My application is casting arrays in a way it should work. To test if I was doing something invalid, I wrote a test code that...
41
by: tech guru | last post by:
Hi, I am doing some mathematical analysis on large numbers in C. The same code runs perfectly in Windows but produces unpredictable results in Unix (like negative numbers or very very big...
10
by: Keith Halligan | last post by:
I'm switching from the HP-UX compiler aCC 5.55 to aCC 6.13 and I get the following error: "templateptr.h", line 20: error #2289: no instance of constructor "defclass::base::base" matches the...
27
by: Dave | last post by:
I'm having a hard time tying to build gcc 4.3.1 on Solaris using the GNU compilers. I then decided to try to use Sun's compiler. The Sun Studio 12 compiler reports the following code, which is in...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.