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: 30
Members Online: 0

Registered Members: 82841
Newest Member: and3rv1sh
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Page 2 of 2 < 1 2
Author

RE: C++, If statement problems


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 05-09-08 01:35
hacker2k wrote:
He's using std. He doesn't need it. It works fine without including it with g++.

@ Coder Disaster: A.) I see why you picked that nick.
B.) Use strings. Much simpler and it's one big feature in C++ that is better than in C.
C.) Just use cin >> instead of cin.getline
D.) You should really be able to figure this out.


Alright. Then, what is the purpose of <string>?

Pwnzall wrote:
#include <cstring> and <string.h> are synonymous. Usually, you either prefix c to use the standard C headers (cstdlib,cstdio,ctime) or you affix it with .h (stdio.h, stdlib.h,time.h). Look around on cplusplus.com (it doesn't implicitly say that, but you can tell when it talks about the C functions and my compiler doesn't complain either).


Yes, yes, I was aware of this... next time, I will be sure to put a / instead of "and" so you won't have to respond. No thanks on the site.


Author

RE: C++, If statement problems


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 05-09-08 01:35
huh?


Author

RE: C++, If statement problems


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 05-09-08 01:45
Zephyr_Pure wrote:
Alright. Then, what is the purpose of <string>?


So that you can just include the data-type (I'm guessing). I don't know much about C++ though, so I'm most likely wrong.
Author

RE: C++, If statement problems


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 05-09-08 02:14
Zephyr_Pure wrote:
sharpskater80 wrote:
Just wanted to let him know that string/cstring are C library headers.


Curious... I was under the impression that <Cstring> and <string.h> were used for string functions, and that <string> was a class that inherited std. Guess I should get back into C++ at some point... been meaning to.


From what I have found, It is safe to assume that it is.
Code

<string> is for the std::basic_string template
(from which std::string is created).
http://bytes.com/. . .62119.html





Code

http://www.cplusp. . .ng/string/
<string>

String class

String objects are a special type of container, specifically designed to operate with sequences of characters.

Unlike traditional c-strings, which are mere sequences of characters in a memory array, C++ string objects belong to a class with many built-in features to operate with strings in a more intuitive way and with some additional useful features common to C++ containers.

The string class is an instantiation of the basic_string class template, defined in <string> as:

typedef basic_string<char> string;

Member functions
(constructor)   Construct string object (constructor member)
operator=   String assignment (public member function)

Iterators:
begin   Return iterator to beginning (public member function)
end   Return iterator to end (public member function)
rbegin   Return reverse iterator to reverse beginning (public member function)
rend   Return reverse iterator to reverse end (public member function)

Capacity:
size   Return length of string (public member function)
length   Return length of string (public member function)
max_size   Return maximum size of string (public member function)
resize   Resize string (public member function)
capacity   Return size of allocated storage (public member function)
reserve   Request a change in capacity (public member function)
clear   Clear string (public member function)
empty   Test if string is empty (public member function)

Element access:
operator[]   Get character in string (public member function)
at   Get character in string (public member function)

Modifiers:
operator+=   Append to string (public member function)
append   Append to string (public member function)
push_back   Append character to string (public member function)
assign   Assign content to string (public member function)
insert   Insert into string (public member function)
erase   Erase characters from string (public member function)
replace   Replace part of string (public member function)
copy   Copy sequence of characters from string (public member function)
swap   Swap contents with another string (public member function)

String operations:
c_str   Get C string equivalent (public member function)
data   Get string data (public member function)
get_allocator   Get allocator (public member function)
find   Find content in string (public member function)
rfind   Find last occurrence of content in string (public member function)
find_first_of   Find character in string (public member function)
find_last_of   Find character in string from the end (public member function)
find_first_not_of   Find absence of character in string
find_last_not_of   Find absence of character in string from the end (public member function)
substr   Generate substring (public member function)
compare   Compare strings (public member function)










Edited by on 05-09-08 02:15
Author

RE: C++, If statement problems

ynori7
Member



Posts: 1486
Location: #valhalla
Joined: 08.10.07
Rank:
God
Posted on 05-09-08 02:45
Zephyr_Pure wrote:
Alright. Then, what is the purpose of <string>?

The way I remember it, some compilers have you #include <string.h> and some you use #include <string>. I think they assume it's a '.h'. In visual c++ you dont put a '.h' on any of the header files.


halls-of-valhalla.org/images/affiliateLogo.png voodoorage.halls-of-valhalla.org/images/smallLogo.png
i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg
ynori7 http://halls-of-valhalla.org
Author

RE: C++, If statement problems

yours31f
Member



Posts: 1678
Location: Dallas Texas
Joined: 27.04.07
Rank:
Elite
Posted on 05-09-08 02:52
ok I will attempt to settle this,

If you #include <iostream> and using namespace std; string and some if the more basic math.h is inherited. Now if he wanted to find the length of the of the string or any other function like that then yes he would have to #include <string>



Debugging is what programmers do to beta software to make it take up more room on your hard drive if it is running too efficiently.


img259.imageshack.us/img259/3713/sigr.png

yours31f@live.com yours31f@yahoo.com rpwd.info
Author

RE: C++, If statement problems


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 05-09-08 02:59
I think this is just a big misunderstanding of where the C++ string class is included from, <iostream>.

Code

#include <iostream>
int main()
{
std::string s("Thursday");
}





<cstring> and <string.h> are for C++ and C compilers respectively, but are both C string libraries.




Edited by on 05-09-08 03:01
Author

RE: C++, If statement problems


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 05-09-08 03:02
For those interested , this is what i have

Code

#include <iostream> //include the input output stream

using namespace std; // using the namespace std
char name[200],password[200],addi[200],final['200']; //define the vars for username and password
char start[] = "start firefox.exe ";
int login();
char newpage();
int main() // start the main function
{
  if(login())//if password is correct
  {   
  system("cls");                       
  cout<<"Loading custom settings...\n";// print loading settings
  system("title Coder Disaster");//change the title to what your handle
  system("color 0a");//change the text color to green with black background
  system("cls");   
  cout << "Welcome Coder Disaster.\n";//print the message Welcome ...
  //system("cd Program Files\Mozilla Firefox\ ");
  cout<< "Opening pre-set web pages.\n";//open web pages
  system("start firefox.exe http://www.computerhope.com/overview.htm");
  system("start firefox.exe http://www.hellboundhackers.org");
  system("start firefox.exe http://www.cprogramming.com/tutorial/");
  cout<< "Web pages opened\n";//print message when oppened
  newpage();
  }
 cin.get();   
 return 0;
}

int login()
{
 cout<< "Enter your name: ";// print the message ,enter your name
 cin.getline(name,200);  // get what the user inputs
 if(strcmp (name, "username") != 0)// check the input against the predefined username, if wrong
 {
   cout<< "Error, try again\n";//print error message, then new line
   system("cls");
   login();//restart the main function
 }
else

  cout<< "Enter your password: ";// print the message enter your password
  cin.getline(password,200);    //get the password from the input
  if(strcmp(password,"password") != 0)//check the password, and if wrong do
  {
   cout<< "Error, try again\n";     // print error message and new line     
   system("cls");               
   login();//restart function
  }   
  else
  {
   return 1;   
  } 
}   
}
 
char newpage()
{
  cout<< "Open new page\n";
  cout<< "http://";
  cin.getline(addi,200);
  strcpy(final,start);
  strcat(final,addi);
  system(final);
  cout<< "Page opened\n"; 
  newpage();     
}   








Author

RE: C++, If statement problems


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 05-09-08 03:06
hacker2k wrote:
So that you can just include the data-type (I'm guessing). I don't know much about C++ though, so I'm most likely wrong.


The purpose of <string> is to define the String class as an inheritant of std so that it can use its functions. If <string> doesn't need to be included by the compiler, then it's likely that the compiler is including it for you or the standard library tries to resolve a descendant by searching the lib paths.

Oh... and no one's "likely wrong" when there's a chance to have an intelligent discussion. Any of us could be, but it doesn't matter... there's a goal here.

Pwnzall wrote:
From what I have found, It is safe to assume that it is.
<snip>


Well, the majority of that could've stayed linked, but it's okay. Yes, string inherits std... which doesn't work the other way around. std does not automatically include string; however, if you make a string declaration, it's possible that either the compiler or the library is "looking for its children".

So, basically, it boils down to a question of whether it's a convention of the language or of modern compilers. Thank you both for contributing to this intelligent discussion.


Author

RE: C++, If statement problems


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 05-09-08 03:26
Ok problem with the code i just posted, after a few seconds (logged in, and loaded pages) its keeps running the newpage function, it waits about 2 seconds then runs it, and continues.

Does anyone know why?


Author

RE: C++, If statement problems


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 05-09-08 03:31
Code
char newpage()
{
cout<< "Open new page\n";
cout<< "http://";
cin.getline(addi,200);
strcpy(final,start);
strcat(final,addi);
system(final);
cout<< "Page opened\n";
newpage();
}




You are making a recursive call, and for some reason not returning a character.

and then new information arrives

uh, christ

You can scope from std, just make sure you include <iostream>.

thanks for putting me in my place
stop being a hot shot, no one cares




Edited by on 05-09-08 20:46
Author

RE: C++, If statement problems


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 05-09-08 03:35
Yer, but why is it doing it after a few seconds , and do i need to return anything?



Author

RE: C++, If statement problems


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 05-09-08 03:36
sharpskater80 wrote:
I think this is just a big misunderstanding of where the C++ string class is included from, <iostream>.


No... it's not. Are all the children of a higher class included when a higher class is included? If you said 'yes', you're a moron. If you include a lower class and it inherits from a higher class, then maybe... but, including a lower class that inherits a higher one is the only way to guarantee that the lower class is included. Case in point: You create a class that inherits from std... Will it be automatically included? No. You'd have to include it manually.


<cstring> and <string.h> are for C++ and C compilers respectively, but are both C string libraries.


Those are function libraries... where is the String class actually defined?

yours31f wrote:
ok I will attempt to settle this,

If you #include <iostream> and using namespace std; string and some if the more basic math.h is inherited. Now if he wanted to find the length of the of the string or any other function like that then yes he would have to #include <string>


Well, you tried... and failed. The majority of the string functions are not included in <string> but, rather, in <cstring> / <string.h>. It's ironic that you say iostream includes this string class declaration functionality but, when it comes down to checking that statement's credibility, it seems like all sources agree that string does not automatically get included and, alternatively, must be included as a descendant of std.

Arguments?




Edited by on 05-09-08 03:39
Page 2 of 2 < 1 2