get() --Confused at usage

This is a discussion on get() --Confused at usage within the C++ Programming forums, part of the General Programming Boards category; i was trying to open a file uing ifstream and storing it as char str I was told to use ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    18

    Question get() --Confused at usage

    i was trying to open a file uing ifstream and storing it as char str
    I was told to use get, but it doesnt work
    The File has multiple lines
    like
    Code:
    hi
              hello
    hi
    Here is my code, could someone tell me whats wrong and how to use get()
    Code:
    #include <iostream.h>
    #include <fstream.h>
    
    int main()
    {
    	
    	char str[300];
    	ofstream c_file;
    	c_file.open("text.txt");
    	c_file<<"Hi\n\tHello\nHi";
    	c_file.close();
    	ifstream a_file("text.txt");
    	a_file.get(str,300, '\n');
    	cout<<a_file.get()<<endl;
    	a_file.close();
    	return 0;
    }
    HACKERS MANIFESTO (NOTE MOST WAS CUT OFF) (PEOPLE SAID IT WAS TOO LONG)
    This is our world now... the world of the electron and the switch, the beauty of the baud.
    We make use of a service already existing withoutpaying for what could be dirt-cheap if it wasn't run by profiteering gluttons, and you call us criminals.
    We explore... and you call us criminals.
    We seek after knowledge... and you call us criminals.
    We exist without skin color, without nationality, without religious bias... and you call us criminals.
    You build atomic bombs, you wage wars, you murder, cheat, and lie to us and try to make us believe it's for our own good, yet we're the criminals.

    Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.

    I am a hacker, and this is my manifesto. You may stop this individual,but you can't stop us all... after all, we're all alike.
    +++The Mentor+++

  2. #2
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    I think you use get like
    char c = cin.get();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Net cpu usage of pthreads?!
    By mynickmynick in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2008, 07:59 AM
  2. Calculating CPU Usage
    By vitaliy in forum Linux Programming
    Replies: 3
    Last Post: 08-21-2005, 09:38 AM
  3. "fin." usage
    By osiris_99 in forum C++ Programming
    Replies: 5
    Last Post: 02-22-2005, 12:52 PM
  4. Win2K Limiting CPU Usage?
    By drdroid in forum Tech Board
    Replies: 4
    Last Post: 03-31-2004, 01:08 PM
  5. confused.. in selecting my line of deapth
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-04-2003, 01:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21