Thread: A program which reads the first characters in a file

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    367

    Post A program which reads the first characters in a file

    Could anyone help me with a code where you can choose to read a special amount of characters in a file (from the beginning and forward), and then output the characters to the screen?

  2. #2
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    do something like this

    ifstream fin;
    char data;
    int n;
    for(i=1;i<=n;i++)
    {
    fin>>data;
    cout<<data;
    }
    -

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    32

    Talking Better to use a char array as a buffer!!

    I think that it would be better to take the whole file content, and put it in a char array buffer..

    Then you can search the array, as you like, may be something like this:

    const int tb_size = 10000;
    char textBuffer[tb_size];
    int i = 0;
    int count = 9;

    for (i = 0;i < count && textBuffer[i] != '\0';i++)
    {
    cout << textBuffer[i] << endl;
    }

    this would print 10 chars

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM