I'm in my first class for C++. Can someone please tell me how to declare a string "consumer"?
Thanks in advance
Printable View
I'm in my first class for C++. Can someone please tell me how to declare a string "consumer"?
Thanks in advance
Or since this is a class and you probably aren't supposed to use the string class:Code:#include <string>
std::string consumer;
100 is an arbitrary size, change it to suit your needs. :)Code:char consumer[100];
If I were to have #include main() can I also have #include <string> in the same code?
Thanks for your response.:D
you're not supposed to #include main().
anyways, yes, you can include more than one header file, and if your program calls for more then one, than you should.
I'm confused! Can you please explain to me why I'm not supposed to use #include main()? Because, this is what my professor is teaching us. :confused:
Your professor is an ignoramus (yes, you can tell him I said that). My advice would be to quit school, buy some good C++ books, and teach yourself!
Anyway, you #include files, not functions - perhaps he meant "main.h" (assuming the file exists in your program workspace)?
#include main() won't even compile, I don't know how you can be taught such abominations anyway. If it is your first class, I won't be a good teacher, so, I'll just let others explain why it is so.
But this post will be aimless if I didn't do something for you, so, here is a basic explanation.
For now, you don't need to know what int main() is, all you have to keep in mind is that everything inside of the brackets is your code and will be executed.Code:// Consider a simple program that does nothing.
// Here's the code.
int main()
{
return 0;
}
See? there's no #include main() thing. #include is designed to include a file into the one which use the directive. For instance, if your file, named "main.cpp" uses #include <stdio.h>, the file named "stdio.h" will be copied into the "main.cpp" when it is loaded into memory to be compiled.
The content of the file is not of import to you right now, just understand that it is here for you to use functions and classes (don't worry if you don't know what it is at present) that weren't available otherwise.
OMG..I'm sorry guys! I'm the ignoramus! lol..
Lack of sleep is a mofo. LMAO
I hope my post here isn't a reflection of what my grade is going to be in this class. :cool:
#include <iostream.h>
#include <string>
int main()
Jeez I'm a goof! Ok so a revised question here.. You can use as many #include as you see fit..correct?
Yes
Umm... Not realy... Header files are there for a purpose. Such as std, a standered namespace, won't work without iostream. Putting to many will just increase file size and make you look noobish...Quote:
Originally posted by Newbie Magic
Yes
>Umm... Not realy...
Why? If you need 10 functions from 10 different headers, you have little choice but to include all of those headers. Not doing so would give unpredictable behavior and make you look noobish. ;)
Oh, I thought he ment just put them there for like no reason, my bad :(Quote:
Originally posted by twm
>Umm... Not realy...
Why? If you need 10 functions from 10 different headers, you have little choice but to include all of those headers. Not doing so would give unpredictable behavior and make you look noobish. ;)
If your professor is honestly teaching to #include <iostream.h>, you should drop the class. That hasn't been legal C++ code for 5 years now.Quote:
Originally posted by §tudent
OMG..I'm sorry guys! I'm the ignoramus! lol..
Lack of sleep is a mofo. LMAO
I hope my post here isn't a reflection of what my grade is going to be in this class. :cool:
#include <iostream.h>
#include <string>
int main()
Jeez I'm a goof! Ok so a revised question here.. You can use as many #include as you see fit..correct?
I still use .h. :p
Only because when I use
It says there is no namespace std.Code:using namespace std;
O_o
get a newer compiler.Quote:
Originally posted by KneeLess
I still use .h. :p
Only because when I use
It says there is no namespace std.Code:using namespace std;
O_o
Visual C++ 6 isn't good enough, what about Dev C++ 4? Yep, even Borland gives me the same error.
So this doesnt compile?:
Code:#include <iostream>
using namespace std;
int main()
{
cout<<"Hello world!";
}
Yes, it does.
But whenever I use it in larger programs (more than one include), it throws errors at me..like this:
Will not compile. Error message: "Could not find include file "stdlib". (That is only part of a program, I know that there is no main() listed here...hehe)Code:#include <stdlib>
#include <fstream>
#include <string>
using namespace std;
Because the C header files are prefixed with c.
E.g. it should be #include <cstdlib>
The C++ standard headers are:
<algorithm> <bitset> <cassert>
<cctype> <cerrno> <cfloat>
<ciso646> <climits> <clocale>
<cmath> <complex> <csetjmp>
<csignal> <cstdarg> <cstddef>
<cstdio> <cstdlib> <cstring>
<ctime> <cwchar> <cwctype>
<deque> <exception> <fstream>
<functional> <iomanip> <ios>
<iosfwd> <iostream> <istream>
<iterator> <limits> <list>
<locale> <map> <memory>
<new> <numeric> <ostream>
<queue> <set> <sstream>
<stack> <stdexcept> <streambuf>
<string> <strstream> <utility>
<valarray> <vector>
Wow, I never knew that.
Thanks Cat. Well it looks like this now
But it's acting like fstream doesn't exist.Code:#include <cstdlib>
#include <fstream>
#include <cstring>
using namespace std;
:rolleyes:
Start a new post then about your specific problem; it's almost certainly an error in your code -- the stream classes changed somewhat from their original pre-1998 incarnations, so maybe you use it in an strange way that is no longer supported. I'd have to see more than the includes to tell what is wrong.