#include
#include
#include
#include
using namespace std;
Bool writeandread (string strDir)
{
//ifstream in (strDir);//the structure of the parameters, can save the open function
String path=strDir + "\ \ iotest TXT";
Ofstream file1.//create a file stream object;
File1. Open (path, ofstream: : out);//open the file;
File1 & lt; & lt;" The HelloWorld "& lt;
Ifstream in;
In the open (path, ifstream: : in);
String s;
In getline (const_cast & lt; Char * & gt; (s.c _str ()), 20, '/n');
Cout
return true;
}
Void main ()
{
String Path="F: \ \ tongyuan";
/* bool iFlag=createDir (Path);
If (iFlag==false)
return; */
//write_text (Path);
Writeandread (Path);
return;
}
I want to read the document in turn two lines, how to do?
This section of the program, a DOS box there is a lot of garbage characters, why? (about 20, explain)
CodePudding user response:
No one, a great god look at the source programCodePudding user response:
String s;
S.r esize (21, 0);//to allocate a memory space for the string and fill 0. More attention to the end of a string of 0
In getline (const_cast & lt; Char * & gt; (s.c _str ()), 20, '/n');//if not allocate space, may be garbled,
Cout
Immediately after you write is to read, plus it will be more reliable,
File1 & lt;
CodePudding user response:
Thank you for the great god, according to your method changed, no noise, but will not be able to output the complete two lines, only:The HelloWorld
Let 's start codi
Not behind
CodePudding user response: