|
-
February 19th, 2004, 06:15 PM
#1
C++ basics
Hello.
I am new to this board and to c++ , so i got couple basic questions to ask:
1.Why do i have to use semicolon after class declaration:
EX:
class CError
{
public:
};
2.Why do we not need to use semicolons after writing code into functions, and after main?I mean,
is there any particular reason for this to be this way , or is this just how c++ is?Is there a rule on
where ";" are suppoused to be ?
3.when you define a function fo some class ,you use :: before the functions name:
void CTest::Function1()
{
}
What are they for??What do they mean?
4. What is the diffrence between | and ||??
5. what is a string?
and do i need to #include <string> to use "string teststring;"?
6.does this line create an object of a ifstream class named fin.
ifstream fin;
7.why do we need a ifstream class object in this function:
getline(fin, szLine);
??
8.why do we use :: in something like std::somefunction. What is the meaning of it?
9.What does this line mean: HWND hWndConsole = NULL;?? Why is it equal to NULL?
10.In the next code snippet:
char szTitle[MAX_PATH];
GetConsoleTitle( szTitle, MAX_PATH );
why does the array have max_path as a # of array items??i tried to chage it but it jsut says that the "newname" is not
defined?
11.HANDLE OutputH; this is a handle to a console inwod as i undrestadn..well what does that mean?
12. also people say that a class in an object, but then what is the object that is done by:
CTestClass objecthere;
?
I know this is kind of a big post , but i am jsut starting out wiht C++ and i got some code snippets and here is some stuff
that i do not undestand. I would really apriciate it so that somone could post an answer to this.
Thx in advance
Last edited by rvr_coder; February 19th, 2004 at 06:21 PM.
-
February 19th, 2004, 06:21 PM
#2
This sounds like an assignment. Many of these questions are easy to find. Please attempt to answer them yourself, and we'll be glad to help you with specifics.
-
February 19th, 2004, 06:41 PM
#3
exectly where can i find them? i check the faq,.,,they are not there...i checked couple of books i got , i can't idn them there either.....and it is not an assignmnet...we get c+= in school only next year....it is just i have been doing some c++ project and used some code snippets from internet , and i don't get these parts.....
-
February 19th, 2004, 06:41 PM
#4
Originally posted by rvr_coder
and it is not an assignmnet...
My butt it isn't.
All of the questions are quite basic and if you read a C++ book, you would be able to get these answers quite easily. Actually, you'd probably only need to read a few chapters/pages.
They probably arn't setup in the book like a normal textbox where it restartes the question and gives you the answer like you're probably looking for.
-
February 19th, 2004, 06:46 PM
#5
this is not an assignment , if you can'r read, i don't have c++ till next year.....i read like 2 c++ books...and i didn';t get any answers at all...books are not too good...but i cna't get ay better ones at a moment....so could you please give at least some answers on some of them?
-
February 19th, 2004, 07:12 PM
#6
Well ... if you read 2 C++ books and you can't answer questions like #1, 2, 5, 7, 10, then those books are either crap or you are not reading, you are just browsing.
Read the books well, you will be able to answer these questions.
You can also visit this page for you to read:
www.cplusplus.com/doc/tutorial/
or you can just google for C++ information.
Also visit this site:
http://cplus.about.com/library/blcplustut.htm
-
February 19th, 2004, 07:18 PM
#7
ok...i think i got question:1,2,3,5,6,8...thx for the resrouces...but i am stuill stuck with the left ones....
#4
i get that | is an bitwise inclusive or operater..i get that it means is that eiather or or and ?
and i right?
but i am still stuck with other ones..
#10:
i get that handle is a way for windows to comunicate with something.....how does it work?
coutl somone give any thought on # 4, 7, 9, 10 and ?
Last edited by rvr_coder; February 19th, 2004 at 07:35 PM.
-
February 19th, 2004, 07:38 PM
#8
|| = or
&& = and
7. why do we need a ifstream class object in this function:
getline(fin, szLine);
Again ... if you look well enough and really READ you can answer all that's left :
Code exmaple using ifstream:
Code:
#include <fstream.h>
#include <iostream.h>
#include <stdlib.h>
int main()
{
ifstream centrada;
ofstream csalida;
cout <<"Se comienza el procesamiento"<<endl;
centrada.open("asterisco.dat");
if (centrada.fail())
{
cout << "Input file opening failed.\n";
exit(1);
}
csalida.open("salida.dat");
if (centrada.fail())
{
cout << "Input file opening failed.\n";
exit(1);
}
char prox;
centrada.get(prox);
while( !centrada.eof())
{
if (prox == '*')
{
cout<<" ";
csalida.put(prox);
centrada.get(prox);
}
else
{
cout<<prox;
csalida.put(prox);
centrada.get(prox);
}
}
centrada.close();
csalida.close();
return 0;
}
In here, instead of getline, we use .get.
-
February 19th, 2004, 07:50 PM
#9
ok..thx , that is a great help to my..cna somone tell me about 9 and 10...also what does | mena if it is not or/and......?
thx
-
February 19th, 2004, 07:58 PM
#10
7. Actually, I'm not sure eagle1 really answered 7.
First, for getline, you just need an istream, not necessarily an ifstream (the input stream does not have to be a file stream). The getline function you are referring to gets input and places it into a string. It is not a member function, so it doesn't know where you want to the input from. For example, you can get input from a file or from the console (cin):
Code:
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::string szLine;
// Read from the console.
std::getline(std::cin, szLine);
// Read from a file.
std::ifstream fin("input.txt");
std::getline(fin, szLine);
}
-
February 19th, 2004, 08:06 PM
#11
hmm...this is interesting...so we use fin..to show that it uses a stream....to read from file??
thx....
could somone alos get an opinion on my previous post....
also i don't yet get number 10 and 12.......
thx in advance
Last edited by rvr_coder; February 19th, 2004 at 08:16 PM.
-
February 19th, 2004, 08:12 PM
#12
Actually, I'm not sure eagle1 really answered 7.
LOL. I actually want him to look for the answers!!! 
Like, what fun will he have if I say that MAX_PATH is a global variable already defined?
-
February 19th, 2004, 08:18 PM
#13
i think i got that MAX_PATH is a global predefines variable but when i try to use other ones in thouse series..it deosn't work...
_MAX_DIR Maximum length of directory component
_MAX_DRIVE Maximum length of drive component
_MAX_EXT Maximum length of extension component
_MAX_FNAME Maximum length of filename component
_MAX_PATH Maximum length of full path
why does it only work with MAX_PATH ?????
what is the diffrence between them....?
also anyone knows what are libraries for? like in dev-Cpp there is a lib folder with files like libwinmm.a ....i use them to be able to use stuff like PLaySound...but what are they in themselves?
Last edited by rvr_coder; February 19th, 2004 at 08:40 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|