hi someone knows why my gcc whe i compile my program usin iostream.h it gives me a lot of errors about the iostream header ......
hi someone knows why my gcc whe i compile my program usin iostream.h it gives me a lot of errors about the iostream header ......
It depends on the errors, but maybe it should be <iostream> without the '.h':
http://www.cplusplus.com/doc/ansi/hfiles.html
Posting code and error messages would be a good idea...
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
here's the code:
and here's the gcc output:Code:#include <iostream> using namespace std; main(){ int k; cout << k; return 0; }
/tmp/cccD88Yz.o: In function `main':
/tmp/cccD88Yz.o(.text+0x1e): undefined reference to `std::cout'
/tmp/cccD88Yz.o(.text+0x23): undefined reference to `std::basic_ostream<char, st
d::char_traits<char> >:perator<<(int)'
/tmp/cccD88Yz.o: In function `__static_initialization_and_destruction_0(int, int
)':
/tmp/cccD88Yz.o(.text+0x50): undefined reference to `std::ios_base::Init::Init[i
n-charge]()'
/tmp/cccD88Yz.o: In function `__tcf_0':
/tmp/cccD88Yz.o(.text+0x7f): undefined reference to `std::ios_base::Init::~Init
[in-charge]()'
/tmp/cccD88Yz.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
Try
g++ prog.cpp
Not
gcc prog.cpp
That is, use the C++ compiler and not the C compiler to compile your code.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
thanks that was useful........
and with linux use g++ prog.ccCode:#include <iostream> using namespace std; main(){ int k; cin >> k; cout << k; return 0; }
or you can always use the emacs complier (which is harder to understand) but pico is easy and basic to use.
Main things i see wrong areCode:#include <iostream> using namespace std; int main() { // need to be returnign something from main. int k = 0 ; // gota intialize k to be something cout << k; return 0; }
A: You arn't returning something from main, and it must be an int.
B: k was allocated but not initialized. so what ever memory k points to, it has soem random crap from what ever was there before
Iamien :you're right something i forgot at time to post the code i didn't copy the initialization...
my code was basic and simplistic and it allowed for the user to enter in what value they wanted for K.. But if you are not allowing for a user to define their own value - then make sure that you have intialized the value first.
If you are using just output statements - you can make your program smaller and faster by going with just an ostream instead of iosteam..Code:#include <ostream> using namespace std; int main() { // need to be returning something from main. int k = 0 ; // got to intialize k to be something cout << k; // output of k return 0; // program ended successfully }
A lot of programs for PDA's and Pagers etc (small hand held devices) use istream and ostream depending on their use.
For a program as small as the one that we have hashed and rehased then it won't make the slightest difference. But make a large program and test it out.
Be sure to 'comment' (i.e // output of k) your work to death - it will help in the long run. It will make the program easy to read and understand and definately easier to transfer into larger projects.
I really hate to nit pick, but just to alieviate any potential confusion: To my knowledge, neither Emacs or pico are/have a compiler. They just use gcc/g++.Originally posted by NIM
or you can always use the emacs complier (which is harder to understand) but pico is easy and basic to use.
~arker
yesOriginally posted by Arker
I really hate to nit pick, but just to alieviate any potential confusion: To my knowledge, neither Emacs or pico are/have a compiler. They just use gcc/g++.
~arker
emacs and pico are the programs that you write the code in.. and gcc/g++ are the compilers