# what's the problem ?



## clmlbx (Mar 24, 2008)

see this code.........this works perfectly in turbo c, borland c 4.5 but gives a error in visual c++ 2008.

code:-


> #include<iostream.h>
> #include<string.h>
> class rab
> {
> ...



few more questions :- 

what does "using namespace std;"  means.................

this above code is out dated as per visual 2008 ..............so what is outdated in it..................


----------



## QwertyManiac (Mar 25, 2008)

clmlbx said:


> what does "using namespace std;"  means.................
> 
> this above code is out dated as per visual 2008 ..............so what is outdated in it..................



VS 2008 probably follows standard C/C++ I assume.

I/O operators such as cout and cin, belong to the std (Standard I/O) class so they obviously have to be referred to as:


```
std::cout and std::cin
```

Instead of just cout and cin like they used to be before standards were kicked into action. So using a 'std' namespace makes all functions and objects of it available to use directly without needing to associate a class ownership prefix.

For example, these both code samples below would work perfectly but you can see which one is sort of easier:


```
#include <iostream>

int main(void)
{
    std::cout<<"Using a :: operator to denote ownership"<<endl;
    return 0;
}
```


```
#include <iostream>

using namespace std;

int main(void)
{
    cout<<"Using a global namespace notation for std"<<endl;
    return 0;
}
```

Now if you are wondering what standards mean, its just like any other standards which apply to any product ensuring its quality and content remains the same worldwide.

Applying standards to code gives one great benefit: Your program becomes portable. A.k.a it runs on all kinds of platforms (Windows or *nix or Mac or etc) without the need of recompilation.

Now for a working version to your code:

```
#include <iostream>
// We exclude .h in standard code
// since the compiler automatically looks
// for the iostream class folders
// and includes the ones necessary.
// Same for all other standard headers.
#include <string>

using namespace std;

class rab
{
    public:
    char r[25];
    int h,b,l;
    void disp();
    void user();
};

void rab::user()
{
    cout<<"Enter your name : ";
    cin>>r;
}

void rab::disp()
{
    l=strlen(r);
    for(b=1;b<=l;b++)
    {
        cout.write(r,b);
        cout<<"\n";
    }
    for(h=l;h>=0;h--)
    {
        cout.write(r,h);
        cout<<"\n";
    }
}

int main(void)
// main() should always return an integer
{
    rab u;
    u.user();
    u.disp();
    return 0;
}
```

P.s. Do indent your code while writing it and also use the [noparse]
	
	



```

```
[/noparse] tags available. Improves readability.

Turbo C is of the yesteryears, its like a decade old. Things have drastically improved even in languages such as C/C++ since then. Standard code gives you more goodies like inbuilt Unicode support, better debugging and many more.

But yes, all code can't be standard. But what part might be, you have to code it that way for the sake of humanity. 

Am attaching my compiled program of your code so that you can see what portable means. I compiled it over GNU C++ Compiler (g++) in Linux. It should run fine on your system too. ( Just rename the x.out to x.exe so that Windows can execute it. Heh, it needs an extension to execute, very stupid indeed.  )


----------



## khattam_ (Mar 25, 2008)

clmlbx said:


> see this code.........this works perfectly in turbo c, borland c 4.5 but gives a error in visual c++ 2008.
> 
> code:-
> 
> ...



where do you get the error??

i one I see is main being void. In new standards, main should always return a value and it should never be void. So make it int and return 0 which indicates successful run.. don't have VC 2008, and haven't analyzed the code.. cud u plz post the errors...

namespace have been introduced in new C++.. the older compilers do not understand namespaces......


----------



## clmlbx (Mar 25, 2008)

^^ Error was that cout was unidentified ...i gues it has to be used like "std::cout and std::cin "as qwertymaniac said


----------



## khattam_ (Mar 25, 2008)

clmlbx said:


> ^^ Error was that cout was unidentified ...i gues it has to be used like "std::cout and std::cin "as qwertymaniac said




yes.. thats it.. alternately, you may write 
using namespace std; 
before main... sorry if it has already mentioned above by somebody.. too lazy to read...


----------

