![]() |
| ||
| problems with reading in file Hello there, I have here a program that reads a txt file taking each word in three columns separated by a comma and storing it to a vector. It has a filter that whenever it sees a comma, it seperates the word from each other. My problem is, whenever I type a phrase or a sentence in a line, the space is considered to a be a beginning of a new line in which ruining the output and producing a run time error. Here's my code and my input txt file. CODE: #include <iostream> TEXT FILE INPUT: STR-000,Login Name,login.html,Notice the first line in the text file input where there is a space between the words Login and Name. Whenever my program reads it, it considers it as a new line, destroying the entire output. I've tried filtering the space by considering it as a char but it still produces the same output. What do you think should I do? Thank you. :) |
| ||
| Re: problems with reading in file Additional question. Does ifstream reads a space as a beginning of a new line? |
| ||
| Re: problems with reading in file If you use getline() on line 64 you will avoid the space problem. getline() will read the entire line, then you can separate it into comma-separated tokens. Line 61 is incorrect -- you should avoid using eof() like that because it will cause problems. Use getline() instead, something like this while( getline(str,inFile) ) |
| ||
| Re: problems with reading in file Quote:
|
| ||
| Re: problems with reading in file Thank you very much sir, it worked. |
| All times are GMT -4. The time now is 10:57 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC