ok so i read about file I/O and the that only allows me to edit files...

let's say i have a program that needs login info.

the user creates his username and password and can then login with it.

but when he closes the program, obviously the info. is lost.. so how can i save this info. to an external file and then retrieve it again when he runs the program so that he can login straight away ? D:

basically just wanting to save 2 variables and load them when program starts...

btw just need to know how to do this in a win32 console app...

thnx :)

Here's a tutorial. Read it, and come back when you have questions/difficulties.

jeez thnx :)

will edit to post difficulties after reading :D

...

oooh wow i figured it out ;).. well still one more thing.. what if we want to specify to it which line we want it to read?

and also i can use fstream all the time instead of ofstream and ifstream?

also how do i make the software create a text file in a location i specify?

ok only 2 more problems remain...

1. how can i specify which line i want it to read.

2. how can i assign a string variable to the line that i read? i tried this and it didn't work:

string line;
string recName, RecPass;
fstream myFile;

myFile.open("C:\\loginfo");
recName = getline(myFile, line);
recPass = getline(myFile, line);
myFile.close();

i have other code that saves the username and password to the text file which works just need to assign it to a variable once it reads.

gives me an error:

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::basic_istream<_Elem,_Traits>' (or there is no acceptable conversion)

on that line i have recName = getline(myFile,open);

thnx for the help once again :)

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::basic_istream<_Elem,_Traits>' (or there is no acceptable conversion)

on that line i have recName = getline(myFile,open);

thnx for the help once again :)

That is probably because (for as far as I know) getline returns a reference to an istream object. The 2nd argument should be the string you want to put your line in, like

string recName, recPass
      fstream myFile;
      myFile.open("C:\\loginfo");
      getline(myFile, recName);
      getline(myFile, recPass);
      myFile.close();
commented: thnx for ur help :D +1

1. how can i specify which line i want it to read.

You could use a loop that does 2 thing:
1. Check if there are still lines available in the file.
2. Check if the current linenumber is the line number you want.

example:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
    ifstream in("c:/your_file.txt");
    
    int line_number = 4; // change to your needs
    string line = "";
    int counter = 0;
    while (counter != line_number && getline(in, line)) counter++;
    
    cout << "line " << line_number << ": " << line;
}

ahh yea thnx guys :)

man this is a whole load of help :)

i appreciate it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.