-
okay this is my first day of learning C++ and i've got this book here "Teach yourself C++ in 24 hours" and I cant get the complier that came with the book to work. here's my code:
Code:
#include <iostream.h> /*this brings an error of not being able to open file */
int main()
{
cout << "Hello World!\n"; /* this brings an error of undifined symbol */
return 0;
}
Does anyone know how to fix this? The book says I may need to find a different file name for #include but i cant find out what. i can find the file in the directory where the complier is but it's not working :( please help!
drewski
-
What compiler is it? The code you posted should work (I think) in Visual C++ (Microsoft's IDE & compiler) but it might not in other compilers. Try this instead:
Code:
#include <iostream>
int main()
{
cout << "Hello World!\n";
return 0;
}
-
Adding the .h at the end of the library is outdated technique, but the Microsoft compiler likes that (wonder why? heehee). Anyway, in the absence of the .h, you will have to add:
using std::cout; //right after the #include statement
Hope this helps.
substring.
-
Ohhh yeah. Best to use the whole standard namespace:
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!\n";
return 0;
}
-
thanks for the help guys but i figured it out. i don't know what the problem was but i reinstalled my complier and it worked just fine after that.