hi guys,
i wonder how you can can take a string from a particular file and assign that to a variable.

for example here is the file named 'isbn.txt'


and my code, as far is i can write it:

int fromfile()
    string filename;
    ifstream fin;
    string isbn;
    cout << "enter the filename: ";
    cin >> filename;
    if (fin.fail())
        cerr << "error. file not found" << endl;
        return 0;

    //isbn = ?????
    // i dunno how to assign isbn in the file to my isbn variable

I want to assign the isbn from my file (eg. 123-456-789-0)
to the isbn variable in the code.

so if anyone know how to do that, please help.

thank you

std::string isbn;

if you want to read them all into an array

std::vector<std::string> isbn_list;
std::string isbn;

while( fin >> isbn)
Be a part of the DaniWeb community

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