I have a poblem whit the source-code

Hi , i am an beginner i install Blooshed Dev-C++ and i wrote this source-code
but i can't compilie it :
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream.h>
#include <string.h>
using namespace std ;
void main ()
{
    char *username ;
    char *password;
    cout<<"Username";
    cin.get(char *username);
    cout<<"Password:";
    cin.get(char *password);
}
OK first of all, you should not use void main. See the articles, Duoas refers to a person called WaltP who discusses why this is bad.
Second. If it's a standard library with angle brackets you do not put the .h after it. So you could #include <string> or #include "string.h" but not #include <string.h>.
Third, you are redeclaring your variables. When you refer to a variable you do not have to - should not - state the type name again, as that is interpreted as a declaration. You have already declared the variable and should just refer to it by name.
Lastly, why are you including string when you are using char[]? (On that topic, I am pretty sure you cannot declare char* and char[] interchangeably. You should create a char username[80] or something instead, I believe.)
So , it should looks like this:
1
2
3
4
5
6
7
8
9
10
11
#include <iostream.h>
#include "string.h"
using namespace std ;
int main ()
{
   
    cout<<"Username";
    cin.get(char username);
    cout<<"Password:";
    cin.get(char password);
}
Notice that Dev-C++ it outdated: http://www.cplusplus.com/forum/articles/7263/
Here is how the code should look like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream> // no .h
#include <string>
using namespace std ;
int main ()
{
    string username, password; // declares two strings
    cout << "Username ";
    cin >> username; // reads a single word from the user
    cout<< "Password: ";
    cin >> password;

    //Now you may want to do something else

    return 0; // value returned to the OS
}
Last edited on
thanks very much
Topic archived. No new replies allowed.