codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  C++ Read file can`t ifstream line  colddax at 20:35 on Saturday, June 18, 2005
 

Hello.

O.S. RHL 8
Compiler gcc ver 3.2

I need to write a program that opens a datafile and then
opens each line (filename).

I can only get the program to open the last line in the file.

Datafile contents
===================

AZ500.txt
AZ600.txt

the program will only open AZ600.txt

Program Segment

int main(){
// vars

char input[20];
char buffer[20];
string line;
string file;
vector<string> Data;

cout << "Input File : ";
cin >> input;

ifstream inputfile(input);
while (inputfile.getline(buffer,20)){ // should remove \n
ifstream datafile(buffer);

Am I not removing a newline char or something? Is this
preventing the first line from opening?

Thanks for any help in advance.

  Re: C++ Read file can`t ifstream line  colddax at 01:07 on Sunday, June 19, 2005
 

In case any one would like to know I believe I have resolved my problem.

I basically took the strlen of buffer and copied each char except the last
one -- the new line. Result, the program now opens each file.

Btw, the compiler was g++, not gcc.

int main(){
// vars

char input[20];
char buffer[20];
char files[20];
string line;
string file;
int len; //new
vector<string> Data;

cout << "Input File : ";
cin >> input;

ifstream inputfile(input);
while (inputfile.getline(buffer,20)){ // should remove \n
len = strlen(buffer); //new
for (i=0;i <len-1; i++){
files = buffer;
}
ifstream datafile(files);








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: Problem with concatenation
•  how to genrates the crystal report by sending a id at runtime
•  help me
•  pls help me with this..
•  Re: Security - Code verify
•  Job @ EarlySail
•  Job @ EarlySail (perl)
•  IPC problem
•  Re: import contacts of msn/yahoo


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007