I'm not sure why, but this code will compile fine in VS.NET 2003, but not gcc under Linux. It seems to be something with the using statement, almost like it can't find the std stuff. I only posted a small portion of the error messages, but they seem to just repeat over and over. Plus, it was too much to post in one message.
Full source:
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
// displays main menu
int main_menu(void);
// display news sites in file
void print_sites(void);
int main()
{
bool cont = true;
int option = -1;
do
{
// display main menu
option = main_menu();
// switch statement for options
switch(option)
{
case 0:
cout << "Exiting program..." << endl;
cont = false;
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
print_sites();
break;
}
} while(cont);
}
int main_menu()
{
int option;
cout << "*** Welcome to RSS Reader ***" << endl;
cout << "[1] Choose News Site" << endl;
cout << "[2] Add News Site" << endl;
cout << "[3] Remove News Site" << endl;
cout << "[4] Show News Sites" << endl;
cout << "[0] Exit Program" << endl;
cout << "Or enter url: ";
cin >> option;
return option;
}
void print_sites()
{
ifstream sitefile("sites.txt");
string str1, str2, str3;
cout << "\n";
while( !sitefile.eof() )
{
getline(sitefile, str1, '\t');
getline(sitefile, str2, '\t');
sitefile >> str3;
sitefile.ignore(80, '\n');
cout << str1 << endl;
cout << "\t" << str2 << endl;
cout << "\t" << str3 << endl;
}
cout << "\n";
sitefile.close();
}
Part of the error during compile:
Code:
chris@zion rss_reader $ gcc rss_reader.cpp
rss_reader.cpp:81:2: warning: no newline at end of file
/tmp/ccAWoF1y.o(.text+0x50): In function `main':
: undefined reference to `std::cout'
/tmp/ccAWoF1y.o(.text+0x55): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'