Learning C++

Started by
63 comments, last by sheep19 16 years, 3 months ago
For starters, that's C, not C++ (although that isn't the issue here, it doesn't help).

Secondly conio.h is not in standard C++ or C. Visual Studio does not include it.

However, it does include the Windows Platform SDK (as of VS2008 Express Edition, don't know about the full versions) and so you can use the Windows platform methods.

Your link is the same as the previous one. What do you perceive as the problem with using the method I suggested? All of these functions can be replicated using the Windows Platform SDK.

void gotoxy(SHORT X, SHORT Y){	COORD position = {X, Y};	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), position);}void clrscr(){	HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);	CONSOLE_SCREEN_BUFFER_INFO bufferInfo;	GetConsoleScreenBufferInfo(hOutput, &bufferInfo);	DWORD length = bufferInfo.dwSize.X * bufferInfo.dwSize.Y;	COORD start = {0, 0};	FillConsoleOutputCharacter(hOutput, ' ', length, start, NULL);}


Also, that CenterPrint function isn't portable. It needs to get the buffer width and height and then divide them, rather than assuming 80x25 (which, admittedly, is fairly standard).
[TheUnbeliever]
Advertisement
conio.h is an ancient MS DOS header, so that won't work on Windows. As has already been stated, SetConsoleTextAttribute and SetConsoleCursorPosition provide the mechanism to do this on Windows.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
Quote:Original post by TheUnbeliever
For starters, that's C, not C++ (although that isn't the issue here, it doesn't help).

Secondly conio.h is not in standard C++ or C. Visual Studio does not include it.

However, it does include the Windows Platform SDK (as of VS2008 Express Edition, don't know about the full versions) and so you can use the Windows platform methods.

Your link is the same as the previous one. What do you perceive as the problem with using the method I suggested? All of these functions can be replicated using the Windows Platform SDK.

*** Source Snippet Removed ***

Also, that CenterPrint function isn't portable. It needs to get the buffer width and height and then divide them, rather than assuming 80x25 (which, admittedly, is fairly standard).


Sorry, I was a little late, Check this out. It explains it all at the bottom

http://comsc.dvc.edu/UsingVisualStudio6.pdf

Any way your right. again I'm sorry. Thats the part I couldn't under stand. All the doc's and manuals I have gone threw state at the top C++.

Thanks again



Quote:Original post by bigjoe11a
Check this out. It explains it all at the bottom

http://comsc.dvc.edu/UsingVisualStudio6.pdf


No problem. As you can see, it does something pretty similar to what I did. If there's something about it that you still don't understand, I'll try to explain now that I know what you're talking about.

Incidentally, you will often find that information for Visual Studio 6 is confusing, because we're now 3 versions on, and it's changed significantly in that time.

Quote:again I'm sorry


Lack of knowledge is rarely something to apologise about—we're all constantly learning. :-)
[TheUnbeliever]
Quote:Original post by Rocksy
Quote:Original post by bigjoe11a
Quote:Original post by Rocksy
You might want to look at this page... there are some sample assignments in the Challenges section, and the tutorials are helpful as well. Happy coding!


Thanks Rock. But I wanted a real program sample. Just parts of one doesn't help.
I have been able to find lots of samples. I just can't find sample programs. If you get the idea. I fount out that C++ is no where near Basic nor Pascal. So the programming language is no where near the same. I have played with the tutorial that I have. Its just that options from the tutorial are missing from the IDE that I have.

I just think that the tutorial I have is out of date. I wish and I have been looking for an updated one. One thats not even a year old. and thats hard to find.


Hi BigJoe,
I was looking around for some source code for a project, and I came across a site with loads of source code for C++ programs. Different kinds of categories, from games to sorting programs, etc. You might check it out... From what I can tell it's all free (scroll down to the bottom of the page) and it seems to be complete code. But I could be wrong... Planet Source Code

I don't know if this site is very good, as I just found it. However, you can find some similar sites by googling "C++ source code" (you have probably done this, but I'm explaining how I found it..) Anyway, I hope it helps. I checked out a couple of their programs and they looked decent.
Happy coding!
-Rocksy


Bingo, Thanks Rock Thats what I'm looking for.
Quote:Original post by TheUnbeliever
Quote:Original post by bigjoe11a
Check this out. It explains it all at the bottom

http://comsc.dvc.edu/UsingVisualStudio6.pdf


No problem. As you can see, it does something pretty similar to what I did. If there's something about it that you still don't understand, I'll try to explain now that I know what you're talking about.

Incidentally, you will often find that information for Visual Studio 6 is confusing, because we're now 3 versions on, and it's changed significantly in that time.

Quote:again I'm sorry


Lack of knowledge is rarely something to apologise about—we're all constantly learning. :-)


Well I should thank you again for your time. And I also fount a web site that one of your members fount for me, Thanks Rock. and it has options and samples that I need.

Don't worry. You will be hearing from me again

Quote:Original post by TheUnbeliever
Quote:Original post by bigjoe11a
Quote:Original post by bigjoe11a
Quote:Original post by TheUnbeliever
Quote:Original post by bigjoe11a
2) ACSII Chars and colors
Is there an option to use ascii chars and colors. I been looking threw a lot of manuals in the last 4 days and haven't fount a thing.


3) Is there an option or command that will let me do a GotoXY or some thing like that.


These are platform specific, and so are supplied by platform libraries.

Under Windows, these are provided by SetConsoleTextAttribute and SetConsoleCursorPosition, respectively.


Thanks but I don't under stand a word of it.


Or maybe to don't know what I'm asking. Check this link out

Read This


I don't understand the link? It seems to be asking the same as question 2 and yields the same response (amongst others, of course). Possibly I am misunderstanding, so I'll give an example of what I'm talking about.

*** Source Snippet Removed ***

As for ASCII characters, I'm guessing you mean accessing the extended character set? If so, either insert the character directly into the source, or output the code directly (std::cout << char(7); emits a the BEL character — this can actually be produced by the '\a' escape character, but the above works for any code). Of course, this will only work assuming the console uses ASCII characters—if it isn't, there's nothing you can do about it.


I just wanted to let you know that I been playing with this. and well I copy your sample to my project and well I'm getting all kinds of errors

This is not even half of the errors I have

c:\program files\microsoft visual studio 9.0\vc\include\ostream(940): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
c:\documents and settings\joe\my documents\visual studio 2008\projects\hello world\hello world\hello world.cpp(136) : error C2297: '<<' : illegal, right operand has type 'const char [32]'
c:\documents and settings\joe\my documents\visual studio 2008\projects\hello world\hello world\hello world.cpp(136) : error C2563: mismatch in formal parameter list
c:\documents and settings\joe\my documents\visual studio 2008\projects\hello world\hello world\hello world.cpp(136) : fatal error C1003: error count exceeds 100; stopping compilation

If you have some time. All I want to be able to use commands that I used before. All I want to do is use some thing like this

TextColor(#); // The # is the color number, Text Colors
TextBackGround(#); // Text Back Ground color


Sometimes an error at the top of a block of code can cause a cascade of errors to occur because the compiler just can't make sense of the code that comes after it. Then you will get these 100+ errors. It is usually the first error, at the top of the list, that is the true culprit. So read the error message. Now the very top line is where the compiler chocked, but that is in ostream on line 940, which is a library file. Let's assume the library code is not broken. So look at the next line, and see that it is in hello_world.cpp on line 136. Now that is your code, and that is where the real problem is. So go to hello_world.cpp on line 136 and post a few lines of code above and below (and including) that line.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
Quote:Original post by CodeMunkie
Sometimes an error at the top of a block of code can cause a cascade of errors to occur because the compiler just can't make sense of the code that comes after it. Then you will get these 100+ errors. It is usually the first error, at the top of the list, that is the true culprit. So read the error message. Now the very top line is where the compiler chocked, but that is in ostream on line 940, which is a library file. Let's assume the library code is not broken. So look at the next line, and see that it is in hello_world.cpp on line 136. Now that is your code, and that is where the real problem is. So go to hello_world.cpp on line 136 and post a few lines of code above and below (and including) that line.


Ok, This is the error at the top
hello world.h(20) : error C2143: syntax error : missing ';' before '<<'

This is line 20 from my Hello World.h file

std::cout << "Top left..." << std::endl;

From what I can under stand theres a ; missing some where, Like before << signs.
I know what is saying. I just don't get the error. As far as I know there shouldn't be any thing wrong with this code.
Well, it could be a couple of things. Did you #include <iostream> at the top of your file? If not you can get that error because it does not understand std::cout or std::endl. Also, if your source is short enough (like 20 lines or so), just post the whole thing.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.

This topic is closed to new replies.

Advertisement