[SOLVED] G++ --> iostream.h: No such file or directory
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#include <iostream>
using namespace std;
int
main (int argc, char *argv[])
{
cout << "Hello world" << endl;
return 0;
}
Quote:
g++ -o tmp -Wall -pedantic tmp.cpp
./tmp
Hello world
If that works, then please consider these revisions:
Code:
#include<iostream>
#include<string>
class garments
{
string gcode, gtype, gfabric;
int gsize;
float gprice;
float
assign()
{
if (gfabric.compare ("Cotton"))==0)
{
if (gtype.compare ("Trouser"))==0)
gprice=1300;
else if (gtype.compare ("Shirt"))==0)
gprice=1100;
else if(strcmp(gtype,"Trouser")==0)
gprice=1300-1300*0.1;
else if(gtype.compare ("Shirt"))==0)
// Notice that we've already got logic problems...
// ...Probably time to add more parenthesis!
}
return gprice;
}
public:
void
input()
{
cout<<"Enter garment's code:";
cin >> gcode;
cout<<"Enter garment's type:";
cin >> gtype;
cout<<"Enter garment's size:";
cin>>gsize;
cout<<"Enter garments fabric:";
cin>>gfabric;
// Did you want "int" or "float"? Do you want to truncate or round? Etc...
int tprice=(int)assign();
}
...
}
Note how I substituted C++ "string" class for C-style char arrays; and substituted the C++ string "compare()" for old style "strcmp()".
Note, too, that "conio" is for DOS systems. It's totally obsolete in contemporary systems. If you need terminal control, consider a library like ncurses. If you'd like a GUI, consider a toolkit like GTK+ or Qt. And if you just need quick'n'dirty keyboard input, use "cin" and "cout".
Thanks again for your help. Its late night here and have school tomorrow.
Will do the revisions as you said and post the outcome..
Quote:
Note how I substituted C++ "string" class for C-style char arrays; and substituted the C++ string "compare()" for old style "strcmp()".
Yeah we weren't taught about these... atleast yet not..
Quote:
Note, too, that "conio" is for DOS systems. It's totally obsolete in contemporary systems. If you need terminal control, consider a library like ncurses. If you'd like a GUI, consider a toolkit like GTK+ or Qt. And if you just need quick'n'dirty keyboard input, use "cin" and "cout".
Yeah,, I too realised it after i posted the code but removed now..
You have written void main, it means it returns nothing, at the same time you have put, return 0, you need to remove either of the two. i.e.
make it int main or remove return 0.
You have written void main, it means it returns nothing, at the same time you have put, return 0, you need to remove either of the two. i.e.
make it int main or remove return 0.
No, "void main" is just plain wrong. It's just that some compilers decided to allow it.
"int main" is the proper way and adheres to the standard. And it's not like it's much harder to type.
Anyways, when i tried compiling that w/ void main changed to int main, following error pops-up:
Code:
/tmp/ccpdzlRX.o: In function `garments::input()':
garment2.cpp:(.text._ZN8garments5inputEv[garments::input()]+0x21): warning: the `gets' function is dangerous and should not be used.
Anyways, when i tried compiling that w/ void main changed to int main, following error pops-up:
Code:
/tmp/ccpdzlRX.o: In function `garments::input()':
garment2.cpp:(.text._ZN8garments5inputEv[garments::input()]+0x21): warning: the `gets' function is dangerous and should not be used.
That's a warning, not an error. The program should still compile.
It's just reminding you that gets() is dangerous because if the user types in a line longer than the buffer tht you provide it, it could overwrite parts of memory that it shouldn't, and lead to bad things.
Oh I just ran it and its working nicely w/ the only exception that its not accepting value for Garment's fabric.. It just skips it.. Is it because of gets? But gcode, gtype also uses gets to take input and these are working fine. . .
Oh I just ran it and its working nicely w/ the only exception that its not accepting value for Garment's fabric.. It just skips it.. Is it because of gets? But gcode, gtype also uses gets to take input and these are working fine. . .
Thanks anyways..
You do not require the use of char arrays for a string; use the C++ STL string object. Read about it here.
Even if you choose to use STL string objects, I just wanted to say this:
There's another alternative to gets(), called fgets(). It's better because it takes an additional parameter that specifies the size of the buffer. If the line is longer than the buffer, then fgets() will return as much as the buffer can hold (note that the rest of the line is not lost forever, subsequent calls to fgets() will keep returning the remaining parts of the long line until you get to the end).
But it also takes a stream parameter which gets() doesn't have. For reading keyboard input, just use "stdin" (it's predefined in cstdio).
Even if you choose to use STL string objects, I just wanted to say this:
There's another alternative to gets(), called fgets(). It's better because it takes an additional parameter that specifies the size of the buffer. If the line is longer than the buffer, then fgets() will return as much as the buffer can hold (note that the rest of the line is not lost forever, subsequent calls to fgets() will keep returning the remaining parts of the long line until you get to the end).
But it also takes a stream parameter which gets() doesn't have. For reading keyboard input, just use "stdin" (it's predefined in cstdio).
I tried stdin and this time it worked nicely... Thanks a lot mate...
However, during compilation, there were some warnings:
Code:
garment2.cpp: In member function ‘void garments::input()’:
garment2.cpp:33: error: ‘stdin’ cannot be used as a function
garment2.cpp:35: error: ‘stdin’ cannot be used as a function
garment2.cpp:39: error: ‘stdin’ cannot be used as a function
I'd like to know your (or whosoever reads it first) thoughts on these warnings.. I'm not using stdin as function anywhere then why the warning??
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.