-
October 9th, 2009, 06:07 PM
#1
Is this possible?
Hey, I am new to visual basic, and taking a class on it in school.
Anyway, I was wondering if it was possible to have the user input data, and have the data SAVED to a file, so it could be resurrected later.
Help is appreciated. BTW, I plan on staying on this forum for a while, and hopefully getting good.
-
October 9th, 2009, 06:13 PM
#2
Re: Is this possible?
/me looks at sign above door
"Visual C++ Programming"
yep, thought so.
(yes it's possible)
-
October 9th, 2009, 06:13 PM
#3
Re: Is this possible?
Oh, and btw, if this is possible, could someone give me the coding for it? I am very new, and most likely would understand all of the terms within the code.
BTW, a small prize may be awarded.
-
October 9th, 2009, 06:23 PM
#4
Re: Is this possible?
perhaps you misunderstand, this is a C++ forum, not a VB one.
-
October 9th, 2009, 06:36 PM
#5
Re: Is this possible?
OH yeah, very sorry. I meant Visual Studios! I always get those two mixed up.. =/
-
October 9th, 2009, 09:53 PM
#6
Re: Is this possible?
Nevermind, I figured it out, and it is fairly simple.
My next challenge is this: I need to figure out a way to convert letters into asterisks when the user types in any type of character. Is this possible?
-
October 9th, 2009, 09:58 PM
#7
Re: Is this possible?
In C/C++ you can use cin, cout ( in iostream header) to have use input. And you can write your data to file by using ifstream or ofstream (in fstream header).
Btw, you can read more in C/C++ books. Hope it help.
My English is very bad. So tell me if Something I talked make u confuse.
My Ebook Store: www.coding.vn/book.php
-
October 9th, 2009, 10:04 PM
#8
Re: Is this possible?
Thanks for your input Z, however I have already figured out how to do it. Although your way seems much more simple; are you sure it works? Anyhow, this is the code I came up with:
Code:
#include <iostream>
using namespace std;
int main()
{
char message[20];
FILE *test = fopen("test.txt", "w");
cout << "message: ";
cin >> message;
fprintf(test, "%s\n", message);
}
*I took the code from a much more complex program, and reduced the complexity significantly.*
As well, my current issue is figuring out a way to convert characters into asterisks like a password field.
-
October 9th, 2009, 10:16 PM
#9
Re: Is this possible?
hi,
Code:
#include <iostream>
using namespace std;
int main()
{
char message[20];
FILE *test = fopen("test.txt", "w");
cout << "message: ";
cin >> message;
fprintf(test, "%s\n", message);
}
It's ok.
And "asterisks like a password field."
I wonder whether you use console application or windows application.
if you are in console application, maybe you can do it like that :
Code:
void input()
{
char c;
char pass[100];
int i = 0;
printf("Your Pass: ");
c = getchar();
while(c != 13 && i <100)
{
printf("*");
pass[i++] = c;
}
}
My English is very bad. So tell me if Something I talked make u confuse.
My Ebook Store: www.coding.vn/book.php
-
October 9th, 2009, 10:31 PM
#10
Re: Is this possible?
Originally Posted by zkidkid
And "asterisks like a password field."
I wonder whether you use console application or windows application.
if you are in console application, maybe you can do it like that :
Code:
void input()
{
char c;
char pass[100];
int i = 0;
printf("Your Pass: ");
c = getchar();
while(c != 13 && i <100)
{
printf("*");
pass[i++] = c;
}
}
Hmm, I tested it, but it does not work. It only prints 100 asterisks after you input the password.
I was thinking about using a while statement..but I do not think it is possible.
Thanks a bunch though for your contribution.
-
October 10th, 2009, 03:49 PM
#11
Re: Is this possible?
Well, I figured this one out on my own as well, if anyone wants to check it out, here it is:
Code:
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
void InputPassword(string &value);
int main(void)
{
string pass;
cout <<"Please enter your password: ";
InputPassword(pass);
cout << endl << endl;
cout << pass << endl << endl;
}
void InputPassword(string &value)
{
char key;
do
{
key = getch();
value.push_back(key);
std::cout << "*";
}while(key != '\r'); //Quit if Enter is Pressed
}
Yep..the good 'ol do-while.
Last edited by Coding_Bro; October 10th, 2009 at 03:57 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|