关于下面程序的运行问题

tmwanly 2013-03-22 04:16:41

#include "targetver.h"
#include <iostream>
#include <stdio.h>
#include <tchar.h>
#include <map>
#include <string>
#include<fstream>//文件输入输出的流类
#include <sstream>


using namespace std;
ifstream& open_file(ifstream &in,const string &file)
{
in.close();
in.clear();
in.open(file.c_str());
return in;
}
int _tmain(int argc, _TCHAR* argv[])
{
map<string,string> trans_map;
string key,value;
if (argc!=3)
{
throw runtime_error("wrong number of arguments");//debug error
}
ifstream map_file;
if (!open_file(map_file,argv[1])) //debug assertion failed
{
throw runtime_error("no transformation file");
}
while(map_file>>key>>value)
trans_map.insert(make_pair(key,value));
ifstream input;
if (!open_file(input,argv[2]))
{
throw runtime_error("no input file");
}
string line;
while(getline(input,line))
{
istringstream stream(line);
string word;
bool firstword=true;
while(stream>>word)
{
map<string,string>::const_iterator map_it=trans_map.find(word);
if (map_it!=trans_map.end())
{
word=map_it->second;
}
if (firstword)
{
firstword=false;
}
else
cout<<" ";
cout<<word;
}
cout<<endl;
}

return 0;
}


通过编译了但是不能正常运行
...全文
408 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
2826635869 2014-05-09
  • 打赏
  • 举报
回复
引用 21 楼 tmwanly 的回复:
[quote=引用 20 楼 dy106 的回复:] 引用 19 楼 tmwanly 的回复:引用 18 楼 dy106 的回复:楼主考虑重新建立一个工程 Win32 Console Application 我这个就是 Win32 Console Application啊 好郁闷啊 从建效果也一样用你运行好的代码贴上去调试也是0x7607812f 处未处理的异常: Microsoft C++ 异常: 内存位……
终于知道为什么了,忘记加后面了.txt了 太谢谢了[/quote] 哪里加.txt呢 请赐教啊
wchar_t 2013-03-23
  • 打赏
  • 举报
回复
bool open_file(ifstream &in,const string &file) { in.close(); in.clear(); in.open(file.c_str()); return in.is_open(); } 这么写
_sunshine 2013-03-22
  • 打赏
  • 举报
回复
引用 23 楼 tmwanly 的回复:
引用 22 楼 dy106 的回复: 用这种方式应该怎么打开呢?
楼主仔细学学怎么给main函数传参,只要参数传对了,你的方法是对的
tmwanly 2013-03-22
  • 打赏
  • 举报
回复
引用 22 楼 dy106 的回复:
用这种方式应该怎么打开呢?
_sunshine 2013-03-22
  • 打赏
  • 举报
回复
tmwanly 2013-03-22
  • 打赏
  • 举报
回复
引用 20 楼 dy106 的回复:
引用 19 楼 tmwanly 的回复:引用 18 楼 dy106 的回复:楼主考虑重新建立一个工程 Win32 Console Application 我这个就是 Win32 Console Application啊 好郁闷啊 从建效果也一样用你运行好的代码贴上去调试也是0x7607812f 处未处理的异常: Microsoft C++ 异常: 内存位……
终于知道为什么了,忘记加后面了.txt了 太谢谢了
_sunshine 2013-03-22
  • 打赏
  • 举报
回复
引用 19 楼 tmwanly 的回复:
引用 18 楼 dy106 的回复:楼主考虑重新建立一个工程 Win32 Console Application 我这个就是 Win32 Console Application啊 好郁闷啊 从建效果也一样用你运行好的代码贴上去调试也是0x7607812f 处未处理的异常: Microsoft C++ 异常: 内存位置 0x0031f6c8 处的 std:……
重新建立一个 在最后一步的时候不要选Precompiled header,选第一个empty.... 然后自己添加cpp文件 试试
tmwanly 2013-03-22
  • 打赏
  • 举报
回复
引用 18 楼 dy106 的回复:
楼主考虑重新建立一个工程 Win32 Console Application
我这个就是 Win32 Console Application啊 好郁闷啊 从建效果也一样用你运行好的代码贴上去调试也是0x7607812f 处未处理的异常: Microsoft C++ 异常: 内存位置 0x0031f6c8 处的 std::runtime_error
if (!open_file(map_file,file))  //debug assertion failed
    {
        throw runtime_error("no transformation file");//在这一句
    }
_sunshine 2013-03-22
  • 打赏
  • 举报
回复
楼主考虑重新建立一个工程 Win32 Console Application
tmwanly 2013-03-22
  • 打赏
  • 举报
回复
引用 16 楼 dy106 的回复:
引用 15 楼 tmwanly 的回复:C/C++ code?1234if (!open_file(map_file,file)) //debug assertion failed { throw runtime_error("no transformation file"); }
这一句就卡了 0x7607812f 处未处理的异常: Mic……


你用的什么编译器啊,这个是不是和编译器设置有关系呢
_sunshine 2013-03-22
  • 打赏
  • 举报
回复
引用 15 楼 tmwanly 的回复:
C/C++ code?1234if (!open_file(map_file,file)) //debug assertion failed { throw runtime_error("no transformation file"); } 这一句就卡了 0x7607812f 处未处理的异常: Microsoft C++ 异常: 内存位置 ……
楼主确定是把你要打开的文件跟cpp文件放在一个目录下吗?
tmwanly 2013-03-22
  • 打赏
  • 举报
回复
if (!open_file(map_file,file))  //debug assertion failed
    {
        throw runtime_error("no transformation file");
    }
这一句就卡了 0x7607812f 处未处理的异常: Microsoft C++ 异常: 内存位置 0x0030f434 处的 std::runtime_error。 'en them cuz because gratz grateful i r nah no pos supposed sez said tanx thanks wuz was 文本文件里面的内容 通过前面的找到后面的如 输入sez出来的是said
_sunshine 2013-03-22
  • 打赏
  • 举报
回复

#include <iostream>
#include <stdio.h>
#include <tchar.h>
#include <map>
#include <string>
#include<fstream>//文件输入输出的流类
#include <sstream>

using namespace std;
ifstream& open_file(ifstream &in,const string &file)
{
in.close();
in.clear();
in.open(file.c_str());
return in;
}
int main()
{
map<string,string> trans_map;
string key,value;
/*if (argc!=3)
{
throw runtime_error("wrong number of arguments");//debug error
}*/
string file = "1.txt"; //文件里面存:
//Chinese 中文
//English 英文
//Japanese 日文
ifstream map_file;
if (!open_file(map_file,file)) //debug assertion failed
{
throw runtime_error("no transformation file");
}
while(map_file>>key>>value)
trans_map.insert(make_pair(key,value));
ifstream input;
string fil = "2.txt"; //文件里面存:
//Chinese
//English
//Japanese
if (!open_file(input,fil))
{
throw runtime_error("no input file");
}
string line;
while(getline(input,line))
{
istringstream stream(line);
string word;
bool firstword=true;
while(stream>>word)
{
map<string,string>::const_iterator map_it=trans_map.find(word);
if (map_it!=trans_map.end())
{
word=map_it->second;
}
if (firstword)
{
firstword=false;
}
else
cout<<" ";
cout<<word;
}
cout<<endl;
}

system("pause");
return 0;
}


结果:
_sunshine 2013-03-22
  • 打赏
  • 举报
回复

#include <iostream>
#include <stdio.h>
#include <tchar.h>
#include <map>
#include <string>
#include<fstream>//文件输入输出的流类
#include <sstream>

using namespace std;
ifstream& open_file(ifstream &in,const string &file)
{
in.close();
in.clear();
in.open(file.c_str());
return in;
}
int main()
{
map<string,string> trans_map;
string key,value;
/*if (argc!=3)
{
throw runtime_error("wrong number of arguments");//debug error
}*/
string file = "1.txt"; //文件里面存Chinese 中文
English 英文
Japanese 日文
ifstream map_file;
if (!open_file(map_file,file)) //debug assertion failed
{
throw runtime_error("no transformation file");
}
while(map_file>>key>>value)
trans_map.insert(make_pair(key,value));
ifstream input;
string fil = "2.txt"; //文件名
if (!open_file(input,fil))
{
throw runtime_error("no input file");
}
string line;
while(getline(input,line))
{
istringstream stream(line);
string word;
bool firstword=true;
while(stream>>word)
{
map<string,string>::const_iterator map_it=trans_map.find(word);
if (map_it!=trans_map.end())
{
word=map_it->second;
}
if (firstword)
{
firstword=false;
}
else
cout<<" ";
cout<<word;
}
cout<<endl;
}

system("pause");
return 0;
}
tmwanly 2013-03-22
  • 打赏
  • 举报
回复
引用 10 楼 dy106 的回复:
引用 9 楼 dy106 的回复:C/C++ code?1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465#include <iostream>#include <stdio.h>#……
你刚改的我试了 不行啊
tmwanly 2013-03-22
  • 打赏
  • 举报
回复
引用 8 楼 tofu_ 的回复:
这个是做啥?词典啊? 我测试时,第一个文件内容: Chinese 中文 English 英文 Japanese 日文 第二个文件内容: Japanese English Chinese 完美输出: 日文 英文 中文
··· 嗯
_sunshine 2013-03-22
  • 打赏
  • 举报
回复
引用 9 楼 dy106 的回复:
C/C++ code?1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465#include <iostream>#include <stdio.h>#include <tchar.h>……
楼主在传参给main的时候出了问题
_sunshine 2013-03-22
  • 打赏
  • 举报
回复

#include <iostream>
#include <stdio.h>
#include <tchar.h>
#include <map>
#include <string>
#include<fstream>//文件输入输出的流类
#include <sstream>

using namespace std;
ifstream& open_file(ifstream &in,const string &file)
{
	   in.close();
	   in.clear();
	   in.open(file.c_str());
	   return in;
}
int main()
{
	map<string,string> trans_map;
	string key,value;
	/*if (argc!=3)
	{
		throw runtime_error("wrong number of arguments");//debug  error
	}*/
	string file = "xxxxxx"; //文件名
 	ifstream map_file;
	if (!open_file(map_file,file))  //debug assertion failed
	{
		throw runtime_error("no transformation file");
	}
	while(map_file>>key>>value)
		trans_map.insert(make_pair(key,value));
 	ifstream input;
	string fil = "xxxxxxx"; //文件名
	if (!open_file(input,fil))
	{
		throw runtime_error("no input file");
	}
	string line;
	while(getline(input,line))
	{
		istringstream stream(line);
		string word;
		bool  firstword=true;
		while(stream>>word)
		{
			map<string,string>::const_iterator map_it=trans_map.find(word);
			if (map_it!=trans_map.end())
			{
				word=map_it->second;
			}
			if (firstword)
			{
				firstword=false;
			}
			else
				cout<<"  ";
			cout<<word;
		}
		cout<<endl;
	}

	system("pause");
	return 0;
}
楼主可以参考下
tofu_ 2013-03-22
  • 打赏
  • 举报
回复
这个是做啥?词典啊? 我测试时,第一个文件内容: Chinese 中文 English 英文 Japanese 日文 第二个文件内容: Japanese English Chinese 完美输出: 日文 英文 中文
tmwanly 2013-03-22
  • 打赏
  • 举报
回复
引用 6 楼 dy106 的回复:
楼主考虑所要打开的文件是否都在改程序的同一目录下
是在同一目录下
加载更多回复(6)
经常使用电脑可能也遇到过了! 突然‘咚’的一声 提示 内存不能为read 这个问题我以前也遇到过不知道怎么解决 现在终于有办法了!呵呵! 我们就看看是什么原因引起的吧,另外附送一个小工具修复见下面附件 总结下大概以下9个原因 1、驱动不稳定,与系统不兼容,这最容易出现内存不能为 Read 或者文件保护(主要原因) 2、系统安装了一个或者多个流氓软件,这出现 IE 或者系统崩溃的机会也比较大,也有可能出现文件保护 3、系统加载的程序或者系统正在运行程序之前有冲突,尤其是部分杀毒软件监控程序 4、系统本身存在漏洞,导致容易受到网络攻击。 5、病毒问题也是主要导致内存不能为 Read、文件保护、Explorer.exe 错误…… 6、如果在玩游戏时候出现内存不能为 Read,则很大可能是显卡驱动不适合(这里的不适合有不适合该游戏、不适合电脑的显卡)也有可能是 系统版本不够新或者不符合该游戏、显卡驱动 7、部分软件本身自身不足的问题 8、电脑硬件过热,也是导致内存不能为 Read 的原因之一。 9、电脑内存与主板兼容性不好也是导致内存不能为 Read 的致命原因! 以上大概就是目前可以引起系统提示 内存不能为read的原因了 另外软件是针对只是针对部分原因引起的内存不为read所做修复,不是100%有效,大家可以试试看 说下原理: 就是批处理使用 regsvr32命令 将动态链接库文件重新注册 (system32下的所有 .dll 和 .ocx 文件;) 注意:由于修复工具会重新注册 system32下的所有 .dll 和 .ocx 文件 此操作对杀毒软件来说属于敏感操作,所以建议使用修复工具的时候,请禁用杀毒软件,以免部分杀毒误报!jie

65,209

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧