Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

This topic is 5922 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi i need help with this. I want to make a database where the user logs on and types in a name and password. Then their input is checked with an external text file and it compares "strings". So if they tpye bob it looks through the file and if it finds bob, it continues etc... The problem is i cant find how to check for strings. Should it be like bob jim matt and look at each line by line?Please give me any ideas or solutions to fix this problem thanks.

Share this post

Link to post
Share on other sites
String comparison

char* strings, use strcmp
std::strings, use ==

Another (untested) possibility
(your example doesn''t contain passwords, neither does mine)

#include <iostream>
#include <fstream>
#include <set>
#include <iterator>

std::ifstream ifs( "login.txt" ); // The login file

std::set<string> login_table; // The login table

login_table.assign( std::istream_iterator<string>( ifs ), std::istream_iterator<string>() ); // load the file

std::string login; // the input

std::cin >> login; // read the input

if( login_table.find(login) == login_table.end() ) // check the input

std::cout << login << " not found." << std::endl; // fail

std::cout << "You may proceed" << std::endl; // succeed

The rest is up to you.

[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]

Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!