cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
one-dimensional array of char from text
one-dimensional array of char from text document
Nov 13, 2013 at 6:23pm UTC
serrld113
(35)
Hi everyone,
I'm supposed to write a one-dimensional array that uses the first line of a text document but I have no idea how to do this. Can anyone explain to me how?
Nov 13, 2013 at 6:42pm UTC
Computergeek01
(5613)
Sure,
1: Open the target file with an std::ifstream object:
http://www.cplusplus.com/reference/fstream/ifstream/ifstream/
1a: The file path can be a full or a relative path. The relative path perspective depends on the IDE you are using.
2: Make sure the file is open with is_open:
http://www.cplusplus.com/reference/fstream/ifstream/is_open/
3: Since you're using a char array I suggest using the read function:
http://www.cplusplus.com/reference/istream/istream/read/
4: Close the file when you are done:
http://www.cplusplus.com/reference/fstream/ifstream/close/
Topic archived. No new replies allowed.