问题描述
Input1.txt
!
awesome is
Joseph
guess I
answ1.txt
I guess Joseph is awesome !
lab.txt
#include <iostream>
#include <fstream>
using namespace std;
struct nodeinfo
{
string word;
nodeinfo * next;
};
void add (string inputword,nodeinfo ** ref)
{
//create new node
nodeinfo * temp = new nodeinfo();
nodeinfo * temp2 = *ref;
//word into node
temp ->word = inputword;
//since its LIFO,temp is last so its next has to be NULL
temp->next = NULL;
//if list is empty,then the new node is the head
if (*ref == NULL)
{
*ref = temp;
return;
}
//if not empty,we go to last node
//change second to last to temp
while(temp2->next!=NULL)
{
temp2 = temp2->next;
}
temp2->next = temp;
return;
}
void rewind(nodeinfo * lead)
{
if (lead == NULL)
{
return;
}
rewind(lead->next);
cout << lead ->word<< " ";
}
int main(int argc,char *argv[])
{
if (argc >=1)
{
freopen("output.txt","w",stdout);
fstream file;
string filename;
filename = argv[0];
string word;
nodeinfo *head = NULL;
file.open(filename);
while(file >> word)
{
//pass ref pointer and word
add(word,&head);
}
rewind(head);
return 0;
}
}
如果我在这样的代码中手动输入输入文件名“ input.txt”
file.open("input1.txt")
它可以工作,但是我在使用arc时遇到了困难,并争先打开文件并执行我想要的操作。
理想情况下,我会叫我的程序像这样工作
./input1.txt
有人可以向我提供解决方案吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)