how to get all texts from a file by ifstream ?

This is a discussion on how to get all texts from a file by ifstream ? within the C++ Programming forums, part of the General Programming Boards category; Code:
char *str4 = new char[50];
ifstream Inputfile(argv[0],ios::in);
Inputfile.getline(str4, '\n');
sock.Send(num, str4);
Inputfile.close();
delete str4;
It only return one line
...

>>Im using ms vc++ 6.0
And that is your second mistake. Toss that old compiler out and upgrade to free VC++ 2005 Express, especially if you are just learning the c++ language. you will learn some wrong stuff with your compiler.

>> ifstream Inputfile(argv[0],ios::in);
argv[0] is the executable, so unless you meant to send the contents of the executable file, you should probably use argv[1].

>> delete str4;
This should be delete [] str4 since str4 is a character array. Of course, you should generally prefer C++ strings as mentioned by Ancient Dragon, which clean themselves up automatically.

You have to do more than just chage it to string. You have to change the code to work with strings. It might seem like a hassle, but it is probably worth it in the long run.

You have to use the string version of getline, you shouldn't be calling delete with a string (it cleans itself up automatically), and your sock.Send method won't work with the string class as is.

If you can change the sock.Send method, you should have it take a string itself or at least a const char * since it probably doesn't need to actually modify the string. If you do that, then you can pass the string with c_str as shown.