C ++中的文件处理问题 [英] Problem with File Handling in C++
本文介绍了C ++中的文件处理问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,
我在下面给出的代码中遇到一些问题,为什么line参数不起作用?
/ /////////////////////////////码//////////////////// //////////////////////
Hey,
I am having some problem in the code given below, why "line" parameter is not working?
//////////////////////////////Code//////////////////////////////////////////
#include<iostream>
#include<fstream>
using namespace std;
void Edit_Line(string path,int Delimer,int line,string sLine)
//Parameter "line" is giving large values"
{
char* temp;
temp=new char[50];
temp[49]='\0';
bool Loopbrk=false,isWritten=false;
int iCounter=0,iDelimer=0,i=0,count=0;
fstream myfile(path);
char keystroke;
while(myfile.good())
{
myfile.get(keystroke);
if(keystroke=='\n')
iCounter++;
while(iCounter==line)
{
myfile.get(keystroke);
if(keystroke=='$')
iDelimer++;
while(iDelimer==Delimer)
{
if(isWritten==false)
{
int iCounter=0;
int size=sLine.length();
while(iCounter<=size)
{
myfile<<sLine[iCounter];
iCounter++;
}
isWritten=true;
}
myfile.get(keystroke);
myfile<<" ";
i++;
if(keystroke=='$')
{
Loopbrk=true;
break;
}
}
if(Loopbrk==true)
break;
}
if(Loopbrk==true)
break;
}
myfile.close();
delete []temp;
}
void main()
{
Edit_Line("student.txt",2,4,"Hello");
}
////////////////////// /////student.txt//////////////////////////
///////////////////////////student.txt//////////////////////////
l114443$Talha Jamil$samsung$12$17$2004$UnderGraduate$!
l114445$Kamran Javed$jannat123$12$12$2009$UnderGraduate$!
l114093$Imran Khan$pluto123$11$4$2009$UnderGraduate$!
l114444$Jamil Ahmed$origin123$11$12$2009$UnderGraduate$!
l114606$Zain Malik$samsung$9$16$2009$Graduate$!
l114441$Saad Kamran$samsung$11$4$2004$Graduate$!
推荐答案
')
iDelimer ++;
while (iDelimer == Delimer)
{
if ( isWritten == false )
{
int iCounter = 0 跨度>;
int size = sLine.length();
while (iCounter< = size)
{
myfile<< sLine [iCounter];
iCounter ++;
}
isWritten = true ;
}
myfile。 get (击键);
myfile<< ;
i ++;
if (keystroke == '
') iDelimer++; while(iDelimer==Delimer) { if(isWritten==false) { int iCounter=0; int size=sLine.length(); while(iCounter<=size) { myfile<<sLine[iCounter]; iCounter++; } isWritten=true; } myfile.get(keystroke); myfile<<" "; i++; if(keystroke=='
')
{
Loopbrk = true ;
break ;
}
}
如果(Loopbrk == true )
break ;
}
if (Loopbrk == true )
断裂跨度>;
}
myfile.close();
delete [] temp;
}
void main()
{
Edit_Line( student.txt, 2 , 4 , Hello);
}
') { Loopbrk=true; break; } } if(Loopbrk==true) break; } if(Loopbrk==true) break; } myfile.close(); delete []temp; } void main() { Edit_Line("student.txt",2,4,"Hello"); }
////////////////////// /////student.txt//////////////////////////
///////////////////////////student.txt//////////////////////////
l114443
Talha Jamil
Talha Jamil
这篇关于C ++中的文件处理问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文