| | |
Read text into array(Ive searched forums)
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
So say I want to open a text document for reading using an instance of ifstream.open, etc.. etc... So once i open the txt file to read from it, what functions do i use to scan each character and put each character into an an array slot? Ive seen loops of if( i = 0, i < 20, i ++0) etc, but is there anyone who can walk me through it with a little more detail? Thanks
>That confuses me =(
Get used to it. Good programmers are in a constant state of confusion.
>Looks like i have some quasi specifics to investigate! Up Up And AWAY!
Get used to it. Good programmers are in a constant state of confusion.
>Looks like i have some quasi specifics to investigate! Up Up And AWAY!
i did not know there was a getline, how many chars will it default out to, because i also want to do this in binary mode as well with things other then text documents. ill do some testing with that. But also for more technical dirty work, is there a scanchar function or something similar? Something that i can research on msdn.
Last edited by clutchkiller; Jun 20th, 2009 at 7:11 pm.
>That confuses me =(
Get used to it. Good programmers are in a constant state of confusion.
>Looks like i have some quasi specifics to investigate! Up Up And AWAY!
Get used to it. Good programmers are in a constant state of confusion.
>Looks like i have some quasi specifics to investigate! Up Up And AWAY!
•
•
Join Date: Jul 2005
Posts: 1,761
Reputation:
Solved Threads: 283
There are lots of tools available. You can read one char at a time aor you can read delimited text that may be stored as text or converted to numerical types. You can create code to read in a defined group of variables using a single written command. You can read a certain number of bytes at a time. You can read files stored in binary format or as text. There is a Bitset class in the standard template library. Etc.
There are 2 versions of getline(), one for C style strings, that have to have a predifined upper size limit, and one for STL strings that don't need a predifined upper size limit, though they probably have an upper size limit defined someplace that I've never bothered to track down since I've never tried to write something that big. getline() needs some way to now when to stop. It may be the amount of data to put in (C style strings), it may a specified char, or it may be the end of file indicator. The default delimiting char for both versions of getline() is the new line char.
You can learn about all of this stuff by finding a good tutorial or picking up a good reference book. I feel (a) good reference book(s) is/are invaluable if you are serious about writing code, even if it's just for your own personal enjoyment. There are a number of options listed in the sticky post section of this board.
There are 2 versions of getline(), one for C style strings, that have to have a predifined upper size limit, and one for STL strings that don't need a predifined upper size limit, though they probably have an upper size limit defined someplace that I've never bothered to track down since I've never tried to write something that big. getline() needs some way to now when to stop. It may be the amount of data to put in (C style strings), it may a specified char, or it may be the end of file indicator. The default delimiting char for both versions of getline() is the new line char.
You can learn about all of this stuff by finding a good tutorial or picking up a good reference book. I feel (a) good reference book(s) is/are invaluable if you are serious about writing code, even if it's just for your own personal enjoyment. There are a number of options listed in the sticky post section of this board.
Klatu Barada Nikto
>Move file pointer to the end of file using seekg(); use tellg() to get the length of file.
Not likely. While the file is opened in text mode, the seek and tell functions do not necessarily deal in pure byte offsets from the beginning of the file.
Read this FAQ: http://www.c-faq.com/stdio/textvsbinary.html third paragraph
Not likely. While the file is opened in text mode, the seek and tell functions do not necessarily deal in pure byte offsets from the beginning of the file.
Read this FAQ: http://www.c-faq.com/stdio/textvsbinary.html third paragraph
Siddhant Sanyam
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
![]() |
Similar Threads
- Read text file to a certain point (C#)
- How to Read text file into array and skip the delimeters (C++)
- How to insert data read from text file into linked list? (Java)
- read text file into array (C++)
- read text file (C)
- read text file (C#)
- using a "for" loop to read a text file (VB.NET)
- Read In Text help (Java)
Other Threads in the C++ Forum
- Previous Thread: How to use SHFileOperation() ?
- Next Thread: What is wrong?
Views: 693 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






