【发布时间】:2016-09-16 15:43:58
【问题描述】:
#include<iostream>
#include<conio.h>
#include<fstream>
#include<string>
#include<string.h>
#include<vector>
using namespace std;
void main()
{
string read;
string name;
vector<string> myvec;
const char * word;
ifstream in;
in.open("w.txt");
ofstream out;
getline(in,read);
word = strtok(&read[0],",");
while(word != NULL)
{
name = word;
cout<<"Word: "<<word<<endl;
name = name + ".txt";
myvec.push_back(name);
out.open(name);
cout<<"Name: "<<name<<endl;
word = strtok(NULL,",");
out.close();
}
in.close();
system("pause");
}
我遇到的问题是,当我在 ubuntu 终端中运行它时,它会抛出一个错误,这通常表示 out.open() 不会采用字符串名称。
我必须从一个文件中创建不同的文件。那么有没有办法解决这个问题呢?
【问题讨论】:
-
Use a C++11 (or greater) toolchain on your Ubuntu box,或者只是传递
name.c_str()而不是name。 -
你试过
out.open(name.c_str())吗?
标签: c++ linux fstream ifstream ofstream