Archived

This topic is now archived and is closed to further replies.

zer0wolf

ANSI C/C++ compliance of gcc

Recommended Posts

I installed the Bloodshed IDE, which came with gcc 3.2, and it won't run a fairly basic C++ program that I know runs in Windows...
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::endl;

int main()
{
// get the student's name
cout << "Please enter your first name: ";
string name;
cin >> name;
cout << "Hello, " << name << "!" << endl;

// ask for and read the midterm grades
cout << "Please enter your midterm and final exam grades: ";
double midterm, final;
cin >> midterm >> final;

// ask for the homework grades
cout << "Enter all of your homework grades, followed by end-of-file";

// the number and sum of grades so far
int count = 0;
double sum = 0;

// a variable into which to read
double x;

// invariant:
// we have read count grades so far, and sum is the sum of the first count grades
while (cin >> x) {
    ++count;
    sum += x;
}

// write the result
streamsize prec = cout.precision();
cout << "Your final grade is " << setprecision(3)
     << 0.2 * midterm + 0.4 * final + 0.4 * sum / count
     << setprecision(prec) << endl;

return 0;
}
  
It complains about the "string name;" line. WTF is up with this? --------------------------------------------------- laziness is the foundation of efficiency retrospiral.net | llamas! | megatokyo | FreeBSD | gamedev.net | google [edited by - zer0wolf on July 26, 2003 3:48:44 AM]

Share this post


Link to post
Share on other sites
Hmmm... this book sucks...

btw... Thanks guys

EDIT: wow, I feel like such a moron... I should try paying closer attention to the book. It being past 3 in the morning doesn't help much though, I suppose...

---------------------------------------------------
laziness is the foundation of efficiency
retrospiral.net | llamas! | megatokyo | FreeBSD | gamedev.net | google

[edited by - zer0wolf on July 26, 2003 4:00:59 AM]

[edited by - zer0wolf on July 26, 2003 4:06:42 AM]

Share this post


Link to post
Share on other sites