If i get w and c in global in the second one it will auto crash the program, if i call it in local and press anything, after enter it will crash like in the first one, its an long error here.
could you tell what and where at() function is? I don't know about it
The at() function, in this case, is a member function of the standard C++ class string. Perhaps you need to study the documentation for this standard C++ class.
As others suggested you could declare char c globally:
main.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <string>
#include "second.h"
char c; // declare c here as a global
int main()
{
std::cout << "Enter a string: ";
std::string w;
std::cin >> w;
c = w.at(0);
std::cout << c << "\n";
eloop();
}
And then tell the compiler the variable can be used by other .cpp files. second.h:
1 2 3 4 5 6 7 8
#ifndef __SECOND_H__
#define __SECOND_H__
void eloop();
externchar c; // notice the use of extern!
#endif