c++ - 用c++程序创建新的txt文件,用变量命名
问题描述
我创建了一个程序,我想用它创建像 aff1.txt、aff2.txt 等文件。在这些文件中,我想在这里创建一个这样的文本:它将打开文件:text.txt 和它将获取每个句子,将其复制 4700/sentence length 次到每个文件。但它不起作用,当: 时cout << ss << endl;
,它什么也不写入 cmd ,而应该有一些东西,这是之前分配的。我应该怎么办?
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <string.h>
#include <sstream>
using namespace std;
int main()
{
ifstream vstup("text.txt"); // 4700,2700,2200,1700
string vety;
getline(vstup,vety);
vstup.close();
string ss="affn.txt";
char q[vety.length()];
for (int u=0;u<vety.length();u++)
{
q[u] = vety[u];
}
int l=0,m=0,n=0;
int v,i,e,o;
char vl[999999];
//cout << vety.length() << endl;
for (i=0;i<vety.length();i++)
{
//cout << "ss" << endl;
if (q[i]=='.')
{
// cout << "ss" << endl;
v=4700/i;
for (e=0;e<v;e++)
{
//cout << "ss" << endl;
for (o=0;o<i-l;o++)
{
// cout << "ss" << endl;
m=o+e*(i-l);
vl[m]=q[o+l];
}
}
l=l+i;
cout << vl << endl;
n++;
//ofstream aff("aff.txt");
//aff << vl << endl;
//aff.close();
ss[3]=n;
ofstream writer(ss.c_str());
//writer.open(ss.c_str());
writer << vl << endl;
writer.close();
cout << ss << endl;
ss.clear();
}
}
return 0;
}
解决方案
推荐阅读
- neupy - 如何使整数输出层?
- javascript - 扩展 html 组件获取属性不起作用
- python - 按索引第 n 个调用列表列表中的元素
- actions-on-google - 从 DialogFlow 中的 Google 列表中的操作获取参数
- selenium-webdriver - 使用 Protractor 拖放动态创建的 Web 元素
- sql - 在数据库架构中包含评论表
- java - java代码在亚马逊AWS云服务上上传后抛出错误
- bash - AWK -F 打印除最后一条记录以外的所有记录
- java - Android Margin 和 Padding 不适用于 ScrollViews 中的 RecyclerViews
- limesurvey - LimeSurvey - 按 group_order 呈现问题组,然后按 question_order 呈现问题