Welcome to Dream.In.Code
Become a C++ Expert!

Join 150,072 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,781 people online right now. Registration is fast and FREE... Join Now!




File I/O. Problem reading txt files.

 
Reply to this topicStart new topic

File I/O. Problem reading txt files., last letter is displayed twice

#include<wmx010>
2 Feb, 2008 - 11:34 AM
Post #1

D.I.C Head
**

Joined: 19 Jan, 2008
Posts: 75



Thanked: 1 times
My Contributions
CODE

#include <iostream>
#include <fstream>
#include <conio.h>
using namespace std;

int main ()
{
    ofstream saveFile;
    saveFile.open ("Ofstream_Test.txt");

    saveFile << "This is an ofstream test";
    
    saveFile.close();
    

    ifstream openFile;
    openFile.open("Ofstream_Test.txt");
    
    char ch;
    while(!openFile.eof())
    {
        openFile.get(ch);
        cout << ch;
    }
    openFile.close();

    _getch ();
}


Problem: It displays: This is an ofstream testt the last letter is repeated twice.
User is offlineProfile CardPM
+Quote Post

#include<wmx010>
RE: File I/O. Problem Reading Txt Files.
2 Feb, 2008 - 12:38 PM
Post #2

D.I.C Head
**

Joined: 19 Jan, 2008
Posts: 75



Thanked: 1 times
My Contributions
ALSO:

CODE

#include <iostream>
#include <fstream>
#include <conio.h>
using namespace std;

int main ()
{    
    fstream file ("fstream_test.txt", ios::in|ios::out|ios::trunc);
    file << "If you can't be a good example";

    static char str[100];

    file.seekg (10, ios::beg);
    file << "HELLO";

    file.seekg(ios::beg);
    file.getline(str, 100);
    cout << str;

    file.close();

    _getch ();
}


I want to add the string "HELLO" 10 positions after the begging. But what it does is that it replaces the current letters with the ones in the string. Is there any way to add letters to the string without replacing them ?
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 11:06PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month