| | |
How do I read from a file into a char*
![]() |
>could someone please tell me what I need to use for this?
Something besides char* because you obviously don't know what you're doing. I'd suggest using the string class, then you can use the c_str member function to get a pointer to const char for your hash function.
Something besides char* because you obviously don't know what you're doing. I'd suggest using the string class, then you can use the c_str member function to get a pointer to const char for your hash function.
In case you were wondering, yes, I do hate you.
•
•
Join Date: Oct 2006
Posts: 6
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
std::string tmp; //temp string value char* temp=""; //Temp value to hold strings ifstream dict, input; //input files for the dictionary file and the article file ofstream outfile; //outfile file dict.open("words08k.txt", ios::in); while (!dict.eof()) { dict.getline(str,20); hsh.insert(temp); }
This is without using the std:string, it compiles correctly this way, but crashes when it reaches dict.getline . the input file is a text file with a word on each line.
a simple example is
ahead
angst
angular
I know my hash functions work fine, I've tested them, I just need a way to get my input into a char* variable before I pass it to the hash function.
on line 1 you have
but, I think that you should assign this pointer to some memory before you use it, i.e. something like
Also, you have
but, you don't declare
If you fix these bits then you might have more luck.
cpp Syntax (Toggle Plain Text)
char* temp=""; //Temp value to hold strings
cpp Syntax (Toggle Plain Text)
char *temp = new char;
cpp Syntax (Toggle Plain Text)
dict.getline(str,20); hsh.insert(temp);
but, you don't declare
str at any point?If you fix these bits then you might have more luck.
![]() |
Similar Threads
- Move file pointer to read next file value (C++)
- read from file help (C++)
- write and read to file (C++)
- how to read a file from client side without browsing (ASP.NET)
- Help with file read/write plz (C)
- C++ How can read from file.txt & where can save this file(file.txt) to start reading (C++)
- create, write & read file to/from folder (C++)
- Read in a file and store in char array (C)
Other Threads in the C++ Forum
- Previous Thread: question about vector .. please help
- Next Thread: Locker Puzzle
Views: 1344 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for C++
algorithm api array arrays assignment beginner binary browser c++ c/c++ calculator char class classes code compile compiler constructor conversion convert count delete desktop display dll dynamic encryption error exception file files fstream function functions game givemetehcodez graph gui helpwithhomework homework i/o iamthwee input int integer lazy library linked-list linker list loop looping loops math matrix member memory newbie news number object objects opengl output parameter path pointer pointers problem program programming project random read recursion recursive reference sort sorting spoonfeeding string strings struct student studio template templates text time tree undefined variable vc++ vector video visual win32 window windows winsock






