-
major problemz!!
Hi~
I am using the fstream modes to open and read files. I want to read characters from the files and assign them to different variables so I can store them and display them later. Is there any way to do this?? I need this really urgent ..I tried many ways and I keep getting gerenal protection error ..!! Please helP~
~secyw~
-
You could try to store the characters into an array. That would be the way I would do it.
-
-
Ok Adrian, What does "Med venlig hilsen" mean? I asume it is Jerman??
-
>>> Ok Adrian, What does "Med venlig hilsen" mean?
Roughly, "With friendly greetings".
>>> I asume it is Jerman??
You mean German? No. Look at my "Location:" line over to the left!
-
FYI:
"Mit freundlichen Gruessen" or short "mfg" is the german term for it ;)
-
Hi~
THis is my code and it keeps ..stating ..general protection error.
#include <fstream.h>
#include <stdlib.h>
#include <string.h>
#include <io.h> // Header file that includes the 'EOF' function
void main ()
{
ifstream new_name; // Declares input stream
new_name.open ("c:/files/names.txt", ios::in); // Opens the textfile
if (!new_name) // Checks to see if file is in the disk
{
cout << "Error opening file.\n"; // Displays information on to the screen
exit(1); // Exits the program
}
char *name [100]; // Declares the variable as type char with maximum of 80 characters
char *lname [100];
int age [20];
int a =0;
while (new_name)
{
new_name >> name [a] >> lname [a] >> age [a];
new_name.ignore(131,'\n'); /* skip up to and including the first newline
character it encounters or to skip 133 characters (maximum amount of characters in 1 line)*/
a++;
eof(1); // Ends the loop when it is at end of file
}
new_name.close(); // Closes the file
}
-
This doesn't crash, but I'm not sure it is doing what you want, you don't seem to be doing anything with the results...
.
.
.
char name [100]; // Declares the variable as type char with maximum of 80 characters
char lname [100];
int age [20];
int a =0;
while (new_name)
{
new_name >> name >> lname >> age [a];
new_name.ignore(131,'\n'); /* skip up to and including the first newline
character it encounters or to skip 133 characters (maximum amount of characters in 1 line)*/
a++;
eof(1); // Ends the loop when it is at end of file
}
.
.
.
-
Jerman oh my I can not believe I messed that up! I must have been tired! I usualy work 10.5 hours a night(8:15pm - 6:45am) and then sit at my computer for another hour before I go to bed. My bad. And I didn't even notice Denmark. Thanks for telling me though.