473,321 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Reading and writing files in linux programming in C++

Hey!

I am making a server and a client like FTP, but my own design. want
users to be able to login with usernames and pwords, which I have
stored in a file. My problem is, that i can't read from the file,
right now i have the following:

int main()
{
struct utmp current_record;
int utmpfd;
int reclen=sizeof(current_record);

if((utmpfd = open(UTMP_FILE, O_RDONLY)) == -1)
{
perror( UTMP_FILE);
exit(1);
}
.......

And it seems to work, cause i get a value for my filedescriptor. But
how do I acces the single lines in the file?

Can I use ifstreams? (This have worked for me in windows programming
earlier, but I think there is a difference in Linux).

I would be greateful if anybody could give me some hints, or help me
understand what to do better, cause I'm pretty lost.

Thank you for your help in advance.

Y.S.

Bo
Jul 23 '05 #1
2 1837
http://cplusplus.com/ref/cstdio/ has reference for stdio.h where you
may find out what functions you use to read from files. It's old
c-style way to do things with files.
to read files using c++:

#Include <fstream>
#include <string>
....
std::string str;
std::ifstream input (UTMP_FILE);
while(std::getline(input,str)){
//..new line read
...
//..do something with str
}
//read until the ond of file, or there was a error...

Jul 23 '05 #2
Bo Huge wrote:
Can I use ifstreams? (This have worked for me in windows programming
earlier, but I think there is a difference in Linux).


std::ifstream is a standard C++ class. There should be no noticeable
difference.

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: christos panagiotou | last post by:
hi all I am trying to open some .raw files that represent images (256x256, 8 bit per pixel, no header) in a c++ program I cannot copy paste the module here as it uses a method from the VTK...
4
by: john smith | last post by:
Hi, I have a file format that is going to contain some parts in ascii, and some parts with raw binary data. Should I open this file with ios::bin or no? For example: filename: a.bin number of...
4
by: GlesgaMick | last post by:
Ok, it must be one of the most fundamentally useful things in a programming language, to be able to read and write files. I want to know how i can do this in Javascript. I want to open a text...
5
by: Jeong-Gun Lee | last post by:
I'm writing a code of writing a value to a specific memory address. ================================================================= #include <stdio.h> int main() { long air; long...
10
by: aceto | last post by:
Hi. I'm sorry for my bad english, but it's not my motherlanguage. I need to read data from a webcam and display the images on DOS . So, how can i show this images? i have to translate the data...
10
by: Bob | last post by:
Hi there, Can anyone point me to anything relating to using XP's built-in CD writing support from VB.Net... or even C#, or classic VB...? I just want to write files to the CD and finalise the...
2
by: Robert Reijntjes | last post by:
Hi, I need to read/write data from/to binary files that have an already defined. This means I can't define classes with the attribute. The files also have arrays with variable length. This...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
26
by: vlsidesign | last post by:
I am a newbie and going through "The C programming language" by Kernighan & Richie on my own time (I'm not a programmer but I want to learn because it can save me time in my normal job, and it is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.