Page 1 of 1

Bizarre compiler warnings

Posted: Mon May 15, 2006 8:53 am
by Dzhefri
I've never had any weird problems getting my submitted code to be compiled, but all the sudden I can't figure out what's going on.

My C++ program begins:

1 #include <iterator>
2 #include <ctype.h>
3 #include <iostream>
4 #include <vector>
5 #include <algorithm>
6
7 using namespace std;
8
9 string to_caps(const string s) {
10 string out;
11 for (int i = 0; i < s.size(); ++i) {
12 out += toupper(s);
13 }
14 return out;
15 }

and so on. (I didn't include line numbers in my submitted code; they're added here for your convenience.) I'm then told my code won't compile, and returned the following error messages:

Here are the compiler error messages:

04576192_24.c:9: syntax error before `('
04576192_24.c:11: `s' was not declared in this scope
04576192_24.c:11: parse error before `;'
04576192_24.c:20: parse error before `{'
04576192_24.c:24: syntax error before `='
04576192_24.c:26: `s1' was not declared in this scope
04576192_24.c:26: `s1' was not declared in this scope

and so on. This compiles just fine on my computer here, using "powerpc-apple-darwin8-g++-4.0.0 (GCC) 4.0.0 20041026 (Apple Computer, Inc. build 4061)". I've tried submitting both by uploading the file on the submit-o-matic and also by cutting and pasting the code there -- it doesn't make any difference. Can anybody figure this one out?

Posted: Mon May 15, 2006 10:55 am
by mf
Try to add '#include <string>' to your program.

Posted: Mon May 15, 2006 7:06 pm
by Dzhefri
Yeah, that fixed it! (Feeling pretty dumb, though!) Any idea why it would still compile on my machine though?

Posted: Tue May 16, 2006 1:21 am
by Carlos
maybe your compiler added string header file automatically...or it was included by another header file.