Follow us on Twitter!
Understanding is the answer, hatred is the problem, and hackers are the slaves abused and destroyed in the process of peace online - Deshouleres
Saturday, April 19, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 30
Guests Online: 29
Members Online: 1

Registered Members: 82835
Newest Member: phanton2043
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

C++ functions


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 14-07-06 01:59
im having and issue with with a function

Code

#include <cstdlib>
#include <iostream>
#include <string>
//When i do int it is bolded in my complier and "string" is not i do have
//the include string but nothing seems to be working.
//the errors sayes " 'string' undecleared "
string Username()   
{
       return "Bob";
       }
using namespace std;

int main(int argc, char *argv[])
{
    cout << Username() << endl;
   
    system("PAUSE");
    return EXIT_SUCCESS;
}





ty for your time

~zer0pain~


Author

RE: C++ functions


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 14-07-06 02:08
Well, sorry I don't really understand what you mean but if you don't even include the int, let's say before string it works fine if you want the ouput as "bob".

#include <cstdlib>
#include <iostream>
#include <string>
string Username()
{
return "Bob";
}
using namespace std;

int main(int argc, char *argv[])
{
cout << Username() << endl;

system("PAUSE"Wink;
return EXIT_SUCCESS;
}



Author

RE: C++ functions


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 14-07-06 02:20
Well duh! :p You try and use an std::string before you declare "using namespace std;" so either modify your code so it looks like this..

Code

#include <cstdlib>
#include <iostream>
#include <string>

std::string Username()
{
return "Bob";
}

int main(int argc, char *argv[])
{
std::cout << Username() << std::endl;

system("PAUSE");
return EXIT_SUCCESS;
}





or just move the "using namespace std;" above your function definition like so..

Code

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

string Username()
{
return "Bob";
}

int main(int argc, char *argv[])
{
std::cout << Username() << std::endl;

system("PAUSE");
return EXIT_SUCCESS;
}



Author

RE: C++ functions


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 14-07-06 03:37
what does the
Code
using namespace std;


do
i havent gotten that far and my complier puts in in there and the book i have uses a differnt complier!

ty 4 u time
~zer0pain~


Author

RE: C++ functions


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 14-07-06 03:47
The "using namespace std" simply tells the compiler to use the names defined in the standard library as if they were functions that you defined in your program yourself pretty much. I suggest you continue to read further along in the book because they are bound to explain it sooner or later, and as a side-note, "using namespace std" isn't considered a good programming habit and should not be used unless you are really really lazy. PfftWink