首页 > 解决方案 > 用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;
}

标签: c++stringfilevariablesfstream

解决方案


推荐阅读