I am trying to use C++ (in Visual Studio 2008) to create a program that I first made using Visual Logic.
The program is supposed to check the users input with an external text file. The external text file just has the username's and passwords...
https://sites.google.com/site/sharearea404/
I tried using arrays (ex: "char u[10]") because that is what I had to use in Visual Logic, but then the first username (I tested it with cout) " "peanut butter" " would read out " "peanut ", so I assume the space in between peanut and butter is screwing up the array? I googled that problem and tried to put add a for loop code that would skip the space using \n. It didn't work.
I moved on to using "strings" because it would ouput peanut butter correctly, but now I can't figure out how to make a for loop that will check through all the names and passwords to see if the user input for a username exists in the external text file.
Thanks for any help and advice you can give me in advance.
This is the mess that I have now...
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
string Username, Password, userx; int counter = 0;
ifstream unpwfile ("C:\\Users\\Daniel\\Desktop\\usernames.txt");
if (unpwfile) // note just test the file object
{
while (! unpwfile.eof() )
{
getline (unpwfile,Username);
getline (unpwfile,Password);
//TEST LINE// cout << "User: " << Username << "\n" << "Pass: " << Password << endl;
}
unpwfile.close();
}
//TEST LINE// else cout << "\n" << " Error: 'usernames.txt' could not be located." << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
// Get username and pass from user
cout << "Please enter your username" << endl;
cin >> userx;
//TEST LINE// cout << Username << Password << userx;
{
cout <<"\n\n\n\n\n\n"<< userx << "\n\n\n";
for (int i = 0; i < 10; i++)
{
if (userx == Username)
cout << "congratulations you finally got the forloop to work" << endl;
else
cout << "Username not found" << endl;
}
}
system ("PAUSE");
return 0;
}