vendredi 26 avril 2019

C++ exception: std::out_of_range at memory location 0x003DF4C0

I am making a C++ program that gets phones from a list of phones and makes a vCard file off of them. However I'm having problems with the copying of the phones over to the file, which is a string replacement off of a template. How can I fix this?

I've tried looking into this site for some solutions but none of them are about ofstream, which is what I'm using to do this.

int main()
{
    string fileDest;

    string vCardTemp = "BEGIN:VCARD\nVERSION:3.0\nTEL;TYPE=WORK,MSG: phonehh\nEND:VCARD\n";

    cout << "Input file destination...\n"; 

    cin >> fileDest;

    cout << "Analyzing data...";


    ifstream inFile;
    inFile.open(fileDest);

    if (!inFile)
    {
        cout << "Error! File doesn't exist or can't be opened.";
        cin.ignore();
        exit(0);
    }

    cout << "File found. Dissecting...";

    string line;

    string finalvCard = "";
    string copy = vCardTemp;
    while (getline(inFile, line))
    {
        istringstream iss(line);

        copy.replace(copy.find("phonehh"), 7, line);

        //finalvCard += copy;
        finalvCard.append(copy);

        cout << " - " + line + " written to vCard.\n";
    }

    cout << "\n\nFinished vCard conversion. Where do we store this (include filename)?\n";

    string dest;

    cin >> dest;

    ofstream file(dest);
    file << finalvCard;

    cout << "File stored! Cya!\n";
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire