Newbies and Beginner Programmers come!

Started by
14 comments, last by ThomasSauder 20 years, 6 months ago
Hello, I just thought that I would create basic C++ tutorials through examples to help people out. Now, what I will do is send out the source to people who ask. So far I've gotten 2 samples going. The first one is: Chapter 1 - Strings and Basics The second one is: Chapter 2 - If and While Loops and Basics The code is fully commented to help the user understand what's going on. Well, here's the code from chapter 1 to give you guys a basic idea of what it's like.

// This program just gets the user to input something and displays

// it back with a little border.


#include <iostream>
#include <string>

using namespace std;

int main()
{
    cout << "Welcome to the test program using strings" << endl;
    cout << "Enter a one word text" << endl;
    
    // Creates a string that grabs their text

    
    string text;
    cin >> text;
    
    // Grabs length of text and declares border size and text

    
    const string Length("You entered " + text + " as your text");
    const string Border(Length.size(), '*');
    
    // Prints border with message

    
    cout << Border << endl;
    cout << Length << endl;
    cout << Border << endl;
    cout << "\tPress Enter to Continue " << endl;
    
    // So the console doesn't disappear

    
    cin.ignore();
    cin.get();
    return 0;
}
I will be finishing each Chapter daily. So every day a new Chapter is out :D. If you have any questions don't hesitate to post back... I'm just trying to help those diving into C++ [edited by - ThomasSauder on September 24, 2003 6:29:48 PM]
Advertisement
Why doesn''t your code work on dev-c++ IDE. I had six errors when I tried to compile, and I''m sure that I write it correctly (I copy and paste it in).

I''ve gotten some books on C++, I try to do the exercises but the code never compiles. What''s wrong.

Thanks

Jakoozie
Jakoozie
I''m actually using DevC++... What are the errors you''re getting?
I get errors like:cout undeclared(first use this function)
and:"Each undeclared identifier is reported only one for each" and:`endl`undecleared (first use this function) and: "parse error at end of input" and: "No such file or directory".

What does it mean?(explain simply, i''m a noob.
thanks



Jakoozie
Jakoozie
I think it means that you didn''t include the iostream file correctly or you''re not using a std namespace. It worked correctly in mine and I''m using Dev-C++.
If that source is thought to be a tutorial you should imho do a lot more commenting.
For example: What is #include?. What is cout? What is a string? Those answers don´t need to be scientifically exact ("a string is a variable that stores texts" is enough) but should give the newb rough overview.
It isn''t meant for someone that has never touched a programming language before... It''s for someone who knows the basics... like, basically just a few if the i/o commands...

If people would want me to add a tutorial page for completely new people, then I will, they just need to ask

Cheers
try typing iostream.h etc and losing using namespace std...
//---------//Ueberbobo//*********
quote:
try typing iostream.h etc


No! No! No!

quote:
and losing using namespace std...


It''s fine for an introductory sample.
Okay, I''m not quite a beginner with programming, however I''ve come across some old things that I seem not to have learned. First of all I have no idea what a "enum" is. A program I''m trying to understand has them all over the place. Can anyone explain to me how to use these?

This topic is closed to new replies.

Advertisement