用c++6.0从键盘输入一个字符串,并以*结尾
2个回答
展开全部
//#include "stdafx.h"//vc++6.0加上这一行.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main(void){
string str;
fstream iofile("text.txt",ios::out);
if(!iofile){
cout << "Create the file failure...\n";
exit(0);
}
cout << "Enter some strings...\n";
while(1){
getline(cin,str);
if(str=="end") break;
iofile << str << endl;
}
iofile.close();
iofile.open("text.txt",ios::in);
while(!iofile.eof()){
iofile >> str;
cout << str << endl;
}
iofile.close();
}
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main(void){
string str;
fstream iofile("text.txt",ios::out);
if(!iofile){
cout << "Create the file failure...\n";
exit(0);
}
cout << "Enter some strings...\n";
while(1){
getline(cin,str);
if(str=="end") break;
iofile << str << endl;
}
iofile.close();
iofile.open("text.txt",ios::in);
while(!iofile.eof()){
iofile >> str;
cout << str << endl;
}
iofile.close();
}
展开全部
#include<stdio.h>
#include<conio.h>
void main()
{
char c,str[256];
int n;
n=0;
while ( 1 )
{ c=getch(); if ( c=='*' ) { printf("\n"); str[n]=0; break; }
printf("%c",c); str[n]=c; n++;
}
printf("%s\n",str);
}
#include<conio.h>
void main()
{
char c,str[256];
int n;
n=0;
while ( 1 )
{ c=getch(); if ( c=='*' ) { printf("\n"); str[n]=0; break; }
printf("%c",c); str[n]=c; n++;
}
printf("%s\n",str);
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询