Hi,
I am having some problems. I started with c++ and so far am finding it a bit confusing. (But i'll get there). the problem i am having right now is, how to convert string to char* . I was told the memcpy is the fastest way but i cannot figure out why it is not working. Oh and is there some tutorial regarding string manipulations in c++.
so i need the lines i read from file to be in a char array since some other c function require it like that. Is there any better way to do this ??Code:#include <cstring> #include <vector> #include <fstream> #include <iostream> // Read a file into a vector void help(char *program) { std::cout << program; std::cout << ": Need a filename for a parameter.\n"; } int main(int argc, char* argv[]) { if (argc < 2){ help(argv[0]); return 1; } std::vector<std::string> file; std::string line; file.clear(); std::ifstream infile (argv[1], std::ios_base::in); int size = 0; while (getline(infile, line, '\n')){ file.push_back (line); size += line.length(); } char *a; a = new char[size]; for (int i = 0; i<file.size();i++){ memcpy(a[i+file[i].length()],file[i],file[i].length()); } return 0; }
thank you
P.S.
Here is the error:
baxyCode:cannot convert ‘std::basic_string<char, std::char_traits<char>, std::allocator<char> >’ to ‘const void*’ for argument ‘2’ to ‘void* memcpy(void*, const void*, size_t)’



LinkBack URL
About LinkBacks


