473,503 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I am learning c++ from c++ Primer( Fourth edition). I am writing a program on page

5 New Member
371 of this book .
# include<iostream>
#include<map>
#include<string>
#include <ios>
#include <stdexcept>
using namespace std;
int main(int argc,char **argv)
{
string map_file,open_file;
map<string,string>trans_map;
string key,value;
if(argc != 3)
throw runtime_error ("wrong no. of argument")
ifstream map_file;
if(!open_file(map_file[1]))
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<<endl;
}
return 0;
}
I am getting an errors :
/home/ankit/wordtransfer.cc||In function ‘int main(int, char**)’:|
/home/ankit/wordtransfer.cc|14|error: expected `;' before ‘ifstream’|
/home/ankit/wordtransfer.cc|15|error: no match for call to ‘(std::string) (char&)’|
/home/ankit/wordtransfer.cc|17|error: no match for ‘operator>>’ in ‘map_file >> key’|
/home/ankit/wordtransfer.cc|19|error: aggregate ‘std::ifstream input’ has incomplete type and cannot be defined|
/home/ankit/wordtransfer.cc|25|error: variable ‘std::istringstream stream’ has initializer but incomplete type|
||=== Build finished: 5 errors, 0 warnings ===|

can anyone please help???
Aug 7 '09 #1
1 2886
mac11
256 Contributor
I can help a little. First, the compiler is telling you what's wrong, so believe it.

For instance, on line #14
Expand|Select|Wrap|Line Numbers
  1. throw runtime_error ("wrong no. of argument")
you need a semicolon on the end of that line.

line #15
Expand|Select|Wrap|Line Numbers
  1. if(!open_file(map_file[1]))
I don't know what you're trying to do and the compiler doesn't either. What is that line supposed to actually do? Are you trying to initialize a string or open a file?

Also you have two variables both named map_file, one a string and one a ifstream.
Aug 7 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2451
by: Darrell | last post by:
Greetings, I wish to purchase Visual Basic (5 or 6) with cost being a major factor. In perusing eBay, I find that there are at least 3 versions of each. I would like to know the differences...
4
7604
by: neil f | last post by:
I'm thinking of investing in a copy of VB6 and was going to go for the Learning Edition (maybe Deluxe). Now I've seen a comment that the Learning Edition does not create .exe files. I presume that...
0
932
by: j_a_s_p_e_r | last post by:
Hi I just got the Deluxe Learning Edition and VC# .NET Standard does not have a lot of the project types. I was disappointed that I couldn't actually do a lot of the projects in the Step by Step...
3
1208
by: Grant Harmeyer | last post by:
Hi All: According to MSDN, C# Standard Edition is good for writing C# programs for Windows or the Web. I am an ASP.NET programmer, and I use both VB and C#. I am looking to doing some hobby...
1
1491
by: Matt S | last post by:
Does the liscense for the VC++.Net 2003 allow the user to purchase a downgrade to VC++.NET 2002? DO I need to buy a standard version of VC++.NET to downgrade? I need to get VC++ 2002, but I can't...
8
1512
by: mark | last post by:
I have just dug out my VB5 Deluxe Learning Edition manuals but I find that I've lost the CD with the VB5 Learning Edition on it. Does anyone know if there is anywhere that I can download it from?...
4
2044
by: Christian Blackburn | last post by:
Hi Gang, I saw this for sale online: Microsoft Visual Basic.NET Deluxe Learning Edition Version 2003. I'm wondering is the CD that's bundled with the learning edition just a digitized version of...
3
2515
by: huangshan | last post by:
hi all I read "C++ Primer, Fourth Edition" , but can't understand this sentence "By making the parameters const references, we allow types that do not allow copying." in "16.1. Template...
6
1508
by: =?Utf-8?B?cGNuZXJk?= | last post by:
I know that VB installs version 3.5 of .Net. I have versions 1.1 & 2.0 on my PC. Can I uninstall versions 1.1 & 2.0 after I install VB? I've been browsing thru books on VB Express Edition. In one...
0
7332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
382
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.