c ++ begginer程序帮助 [英] c++ begginer program help

查看:64
本文介绍了c ++ begginer程序帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对c ++编程很陌生,我需要一些帮助

我的大学分配:

写一个程序读取输入c ++文件并删除评论。

评论可以是oneline(//)和块评论(/ ** /。

的名称是从命令行读取的文件。使用函数和全局

变量如果需要的话。

这里是我的代码。提前致谢

#include< fstream>

#include< stdlib.h>

#include< iostream.h>

#include< stdio.h>

ifstream fp ;

ofstream fpp;


void remove(int kraj,char * line){//删除''//''并保存到文件

int i;

for(i = 0; i< = kraj; i ++){

fpp<< line;

}

}

void proceed(int kkraj,char * line,int lenght){

int i;

for(i = kkraj; i< = lenght; i ++){

fpp<< line;

}


}

void main(){

int i,k,k2,k3;

char filename [12];

char * line;

cout<<"文件的名称是什么" ;;

cin>> filename;

fp.open(filename,ios :: in); //文件来源阅读

if(!fp){

cout<<" \ n error opening\\\
" ;;

退出(0);

}

fpp.open(" no commentary",ios:ut); //文件保存非评论

程序

if(!fpp){

cout<< 打开文件时出错。\ n;

}

while(line = fgets(fp)){

for(i = 0; i< strlen(line); i ++){

if((line [i] ==''/'')&&(line [i + 1] =='' /'')){

k = i-1;

删除(k,行);


}

if((line [i] ==''/'')&&(!begin)&&(line [i + 1] ==''*'')){

k2 = i-1;

删除(k2,line);

begin = 1;


}

if((line [i] ==''*'')&&(begin)&&(line [i + 1] ==''/' ')){

k3 = i-1;

begin = 0;

继续(k3,line,strlen(line));

}


}

fp.close();

fpp.close();

返回;

}


}

I am quite new to c++ programming and I would need some help with
my college assigment:
write a program which reads input c++ file and removes commentary. The
commentary can be oneline(//) and block commentary(/**/. The name of
the file is read from the command line. use functions and global
variables if neccesary.
here is my code. Thanks in advance
#include <fstream>
#include <stdlib.h>
#include <iostream.h>
#include <stdio.h>
ifstream fp;
ofstream fpp;

void remove (int kraj, char *line){ //removes ''//'' and saves to file
int i;
for (i = 0; i <= kraj; i++) {
fpp<<line;
}
}
void proceed (int kkraj, char *line,int lenght){
int i;
for (i = kkraj; i<=lenght; i++) {
fpp<<line;
}

}
void main(){
int i ,k, k2,k3;
char filename[12];
char *line;
cout<<"what is the name of the file";
cin>>filename;
fp.open (filename, ios :: in); //file to read from
if (!fp){
cout<<"\n error opening\n";
exit(0);
}
fpp.open("no commentary", ios:ut); //file to save non commentary
program to
if (!fpp){
cout << "Error opening file.\n";
}
while(line=fgets(fp)){
for(i=0; i<strlen(line); i++){
if ((line[i]==''/'')&&(line[i+1]==''/'')) {
k=i-1;
remove(k, line);

}
if ((line[i]==''/'')&&(!begin)&&(line[i+1]==''*'')) {
k2=i-1;
remove(k2, line);
begin=1;

}
if ((line[i]==''*'')&&(begin)&&(line[i+1]==''/'')){
k3=i-1;
begin=0;
proceed(k3, line, strlen(line)) ;
}

}
fp.close() ;
fpp.close() ;
return;
}

}

推荐答案

srenusa写道:
srenusa wrote:

我对c ++编程很新,我需要一些帮助

我的大学学生:
编写一个读取输入c ++文件并删除评论的程序。

评论可以是oneline(//)和块评论(/ ** /。

的名称是从命令行读取的文件。使用函数和全局

变量如果需要的话。

这里是我的代码。在此先感谢
I am quite new to c++ programming and I would need some help with
my college assigment:
write a program which reads input c++ file and removes commentary. The
commentary can be oneline(//) and block commentary(/**/. The name of
the file is read from the command line. use functions and global
variables if neccesary.
here is my code. Thanks in advance



你有什么样的帮助?想要吗?我没有尝试过,但我不希望这样。

编译。

我想看看删除和继续功能的描述

打算执行。我想看缩进。你的程序

是否允许/ *和匹配* /可以在不同的行上?


< snippage>

What kind of help do you want? I didn''t try, but I would not expect this to
compile.
I would like to see descriptions as to what the remove and proceed functions
are intended to perform. I would like to see indentation. Does your program
allow for the fact the /* and the matching */ can be on different lines?

<snippage>


> void remove(int kraj,char * line){//删除''//' '并保存到文件
>void remove (int kraj, char *line){ //removes ''//'' and saves to file



肯定不是!?说明是删除评论,而不是

表示*是*评论

Surely not!? The instructions were to remove the commentary, not the thing
that indicates it *is* a commentary


fpp.open(no no comment,ios:ut); //保存非评论的文件
fpp.open("no commentary", ios:ut); //file to save non commentary



我基于我在不编译该行时说的话。我认为它应该是

ios :: out。 *两个*更改我只是懒得扫描代码,看看我是否认为它可以编译。

I''m basing what I said on not compiling on that line. I think it should be
ios::out. *Two* changes I just scanned the code idly to see if I thought it
might compile.




我有一个不匹配的问题:无法将ifstream转换为char:

while(line = fgets(fp)){

for(i = 0; i< ; signed(strlen(line)); i ++){

void remove(int kraj,char * line){//删除''//''并保存到文件

我打算将此函数写入新文件所有字符

直到//

字符放在char行中我认为该行[1]

代表第一个字符。

fpp.open(" no appmentary",ios:ut); //文件保存非评论

tipfeller :)

thx为您提供帮助:)


I have a problem with mismatching: cannot convert ifstream to char:
while(line=fgets(fp)){
for(i=0; i<signed(strlen(line)); i++){
void remove (int kraj, char *line){ //removes ''//'' and saves to file
I intended this function to write to a new file all characters
until //
characters are placed in char line and I thought that line[1]
represents the first character.
fpp.open("no commentary", ios:ut); //file to save non commentary
tipfeller :)
thx for your help :)


sr*****@yahoo.com 写道:

我有一个不匹配的问题:无法将ifstream转换为char:

while(line = fgets(fp)){
I have a problem with mismatching: cannot convert ifstream to char:
while(line=fgets(fp)){



什么是''line = fgets(fp)''该怎么办?也许你需要RTFM

关于''fgets''和''ifstream''......

What is ''line=fgets(fp)'' supposed to do? Perhaps you need to RTFM
about ''fgets'' and ''ifstream''...


for(i = 0;我< signed(strlen(line)); i ++){

[..]
for(i=0; i<signed(strlen(line)); i++){
[..]



V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


这篇关于c ++ begginer程序帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆