I have global variable. I want to use char data type so I can insert username in it. So far it’s not working.
In main.cpp
#include "Functions.h"
using namespace std;
char username[50];
int main()
{
cout << username;
}
In Functions.h
char username[50];
In login.cpp
#include "Functions.h"
if(std::strcmp(emp_username, "admin") == 1) {
username = "admin";
}
else
{
username = emp_username;
}
What I want to do is to get the employee username and display it in every function. It works with int data type. Only I don’t know how to use it with char. Please help me with this. Thank you.
Don’t use plain character arrays to store strings, use the
std::stringclass:If you have some weird requirement that forces you to use plain arrays, then compare using:
and the contents can’t be assigned using
=; you need library functions:Finally, if you must have a global variable (which is nearly always a very bad idea), then you need to declare it
externin the header: