要写入txt里面是这样的:
Shoes 59 1.5 0.6 1.0
Shirts 1008 1.2 0.7 0.5
Gloves 17 0.6 1.2 1.2
Curtains 2200 0.5 1.0 2.5
Cutlery 1522 2.5 2.1 1.0
Clocks 100 3.7 1.5 1.1
Calculators 255 2.4 2.0 3.2
Cameras 999 2.0 0.6 2.2
Cardigans 350 3.2 2.8 1.9
Cummerbunds 1000 2.1 2.6 0.2
这个txt文件名叫Warehouse
希望大侠帮忙啊!!!
C++如何写入多行txt文件,并列表输出?
答案:4 悬赏:20 手机版
解决时间 2021-03-08 05:00
- 提问者网友:留有余香
- 2021-03-07 11:59
最佳答案
- 五星知识达人网友:野慌
- 2021-03-07 12:43
#include<iostream>
#include<iomanip>
#include<fstream>
#include<sstream>
using namespace std;
//========================================================
int main(){
ofstream out("wearhouse.txt");
//写入多行TXT文件
int i=1;
double n,m,p,q;
string s;
for(;i<11;++i){
cin>>s>>n>>m>>p>>q;
out<<setfill(' ')<<setw(12)<<left<<s
<<setfill(' ')<<setw(5)<<n
<<setfill(' ')<<setw(6)<<m
<<setfill(' ')<<setw(6)<<p
<<setfill(' ')<<setw(6)<<q<<endl;
}
//列表输出
i=1;
ifstream in("wearhouse.txt");
for(;i<11;++i){
getline(in,s);
cout<<s<<endl;
}
return 0;
}
#include<iomanip>
#include<fstream>
#include<sstream>
using namespace std;
//========================================================
int main(){
ofstream out("wearhouse.txt");
//写入多行TXT文件
int i=1;
double n,m,p,q;
string s;
for(;i<11;++i){
cin>>s>>n>>m>>p>>q;
out<<setfill(' ')<<setw(12)<<left<<s
<<setfill(' ')<<setw(5)<<n
<<setfill(' ')<<setw(6)<<m
<<setfill(' ')<<setw(6)<<p
<<setfill(' ')<<setw(6)<<q<<endl;
}
//列表输出
i=1;
ifstream in("wearhouse.txt");
for(;i<11;++i){
getline(in,s);
cout<<s<<endl;
}
return 0;
}
全部回答
- 1楼网友:话散在刀尖上
- 2021-03-07 16:23
#include
<fstream>
#include
<iostream>
然后main()改写:
void
main()
{
ofstream
fout("output.txt");
cout<<"在11~999之间这样的数有";
fout<<"在11~999之间这样的数有";
for(int
n=11;n<=999;n++)
{
if(hw(n)&&hw(n*n)&&hw(n*n*n)){
cout<<n<<"
";
fout<<n<<"
";
}
}
cout<<"\n";
fout<<"\n";
}
- 2楼网友:神的生死簿
- 2021-03-07 15:33
#include<fstream>
ifstream in("Warehouse.txt");
if(!in) exit(1);
char c[1000]
while(in)
{
cin.getline(c,1000,'\n');
cout<<c<<endl;
}
- 3楼网友:人類模型
- 2021-03-07 14:21
#include <fstream>
#include <iostream>
然后main()改写:
void main()
{
ofstream fout("output.txt");
cout<<"在11~999之间这样的数有";
fout<<"在11~999之间这样的数有";
for(int n=11;n<=999;n++)
{
if(hw(n)&&hw(n*n)&&hw(n*n*n)){
cout<<n<<" ";
fout<<n<<" ";
}
}
cout<<"\n";
fout<<"\n";
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯