The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script for reading .csv file creativeworld Shell Programming and Scripting 3 11-11-2007 11:47 PM
Script for Reading a Password file srirams Shell Programming and Scripting 2 03-07-2007 07:20 AM
Script for reading an input file gzs553 Shell Programming and Scripting 1 10-17-2006 03:55 AM
Reading file names from a file and executing the relative file from shell script anushilrai Shell Programming and Scripting 4 03-10-2006 02:25 AM
script to reading a file vasikaran UNIX for Dummies Questions & Answers 3 07-26-2005 02:28 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-07-2003
Registered User
 

Join Date: Dec 2001
Location: Dublin
Posts: 44
Reading a file into a C++ script

Hi,
I'm trying to read a file in with and assigne the stream to a char * type. I've manged it using the cin.get returning type char, but am having run-time problems returning a char *. For example,

char *pStream = "file.txt";

ifstream from(pStream);
from.open(pStream);

cin.get(pStream, FileSize, '\n');

However, the pStream in cin.get(pStream, FileSize, '\n'); does not seem to work at run-time, as it just hangs.
Txs
Reply With Quote
Forum Sponsor
  #2  
Old 10-08-2003
Registered User
 

Join Date: Dec 2001
Location: Dublin
Posts: 44
Ive sorted this now -
char *pStream = new char[200];
char *pFile = "file.txt";

ifstream is(pFile);
if(!is) error("Cannot open File", pFile);
if(is.good())
{
while(is.get(pStream, 200, EOF))


the problem was that you can't call the ifstream constructor twice ie is.open(pFile) and is.get(pStream)!!

Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0