Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 wow, self teaching C++ is hard...
Index -> Programming, C++ -> C++ Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Thu Sep 09, 2004 10:48 pm   Post subject: (No subject)

omni wrote:
Whats STD stand for (aside from sexually transmitted disease, haha)?


It's a shortened version of standard, as in standard namespace.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Thu Sep 09, 2004 11:13 pm   Post subject: (No subject)

rizzix wrote:
yep not even close to standard. hmm there are technically no libraries with C++. its a standalone language unlike a lot of other languages. but there is the standard template library. that usualy comes with most compilers.


There actually is a standard library for C++. The STL is part of it, but isn't the whole thing.

Things like string, iostream, fstream, etc.

Other languages do have more extensive included libraries, but C++ does have a standard library that covers the basics pretty well, especially when paired with the STL. It should be noted that those languages have both libraries and a "core language". Java could be paired with an entirely different set of libraries, for instance.
omni




PostPosted: Fri Sep 10, 2004 8:58 pm   Post subject: (No subject)

could soemone explain how to open files? Which file to you have to include.. ifstream, ofstream, fstream ??? How to read from files, display contents of files etc..
I find my tutorial confusing, or maybe i'm just tired.
wtd




PostPosted: Sat Sep 11, 2004 12:01 am   Post subject: (No subject)

code:
#include <iostream>
#include <fstream>

int main()
{
   ifstream input_file("Input.txt");
   ofstream output_file("output.dat");

   output_file << "hello world" << std::endl;

   char input;

   input_file >> input;
}
omni




PostPosted: Wed Sep 15, 2004 7:52 pm   Post subject: (No subject)

I have this program:
#include <iostream.h>
#include <conio.h>

int main()
{
char ch;
while(1){
if (kbhit()){
ch=getch();
cout << ch <<"\n";}
}
return 0;
}
When I press a key, the value is stored in 'ch' right? So how do I compare 'ch' to something else?
EX: if (ch ="A") <- is this right, cuse I get an error about nonvalue assignment?
Andy




PostPosted: Thu Sep 16, 2004 3:34 pm   Post subject: (No subject)

well see in c++ = is used to define, not compare, == is used to compare to values, if u were to replace your = with ==, all should be fine, o and you cant conpare a char with a string, so you have to use 'A' instead of double quotes
omni




PostPosted: Thu Sep 16, 2004 8:01 pm   Post subject: (No subject)

o right, forgot about the ==. Thanks
bugzpodder




PostPosted: Sat Sep 18, 2004 8:54 pm   Post subject: (No subject)

if you are going to use STL, better put in "using namespace std;"

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
using namespace std;
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Sat Sep 18, 2004 9:45 pm   Post subject: (No subject)

Not globally though. That can make your executable quite large (and possibly mess up some stuff with the intellisense in MSVC). You can use "using namespace std;" inside you main function (and wherever else you need it too I guess).
Andy




PostPosted: Sat Sep 18, 2004 10:42 pm   Post subject: (No subject)

and that'll decrease the size? sweet...
Mazer




PostPosted: Sun Sep 19, 2004 6:58 am   Post subject: (No subject)

No, it won't decrease the size, but it will make it less than if you have that line in the global scope. But I don't even use it now anyways. I'll just declare something as std::vector or std::string if I need to.
Andy




PostPosted: Sun Sep 19, 2004 1:25 pm   Post subject: (No subject)

hmm but why tho? i mean why would it be different if u declared it globally
wtd




PostPosted: Mon Sep 20, 2004 12:49 am   Post subject: (No subject)

dodge_tomahawk wrote:
hmm but why tho? i mean why would it be different if u declared it globally


I wouln't worry about its affect on executable size (at least not yet), but it's generally bad practice, There's a lot of stuff (classes, functions, etc.) in the std namespace. It's good to keep that boxed up as much as possible.
omni




PostPosted: Fri Sep 24, 2004 8:43 pm   Post subject: (No subject)

what does it mean to overload an operator?
wtd




PostPosted: Fri Sep 24, 2004 9:04 pm   Post subject: (No subject)

omni wrote:
what does it mean to overload an operator?


In C++ you can have multiple functions or procedures (functions which return void) with the same name, as long as they all have different signature. The signature of a function or procedure is composed of three things:


  • The type of value the function returns
  • The name of the function or procedure
  • A list of paremeters (or "arguments") the function accepts


So if we change the parameters the function or procedure accepts, we can have multiple functions with the same name.

Operators are basically just functions or procedures which take two arguments. So we can overload operators to handle data types the built-in operators don't normally deal with. The most common example is probably overloading the << operator to deal with input and output.

code:
class name {
   private:
      std::string first, last;
   public:   
      name(std::string f, std::string l) : first(f), last(l) { }
      friend std::ostream& operator<<(std::ostream& out, const name& n);     
};

std::ostream& operator<<(std::ostream& out, const name& n)
{
   return out << n.first << " " << n.last;
}

int main()
{
   name bob = name("Bob", "Smith");
   std::cout << bob << std::endl;
}
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 30 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: