By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,510 Members | 1,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,510 IT Pros & Developers. It's quick & easy.

Check this program for me. please!!

P: 14
Hello...

How are you every body?

I want from you to check this program..

**************************************************
Suppose that the file inData.txt contains the following data:
Sarah AlSammak alahliunitedbank bh

Write a C++ program that read from the inData file the first string as a first name, the second string as a last name, the third string as a company name and the last string as a country code. The aim of the program is to create an email for the user and store it in outData.txt file.

The email structure is:
Fname_lname@company_name.com.country_code

After the execution, the outdata.txt should contain:

email removed

************************************************** *******************
My soultion is:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>  
  2. #include<fstream>                      
  3. using namespace std;                       
  4.  
  5. int main() 
  6. {         
  7.  
  8.  
  9.  
  10.     string Fname,lname;
  11.     string company_name,country_code;
  12.     char '@';
  13.  
  14.     ifstream infile;
  15.     ofstream outfile;
  16.  
  17.     infile.open("inData.txt");
  18.     outfile.open("outData.txt");
  19.  
  20.     infile>>Fname>>lname ;
  21.     infile>>company_name>>country_code>>endl;
  22.  
  23.     outfile<<"Fname_lname"<<'@'<<"company_name"<<.com<<".country_code"<<endl;
  24.  
  25.     infile.close();
  26.     outfile.close();
  27.  
  28.     return 0;                           
  29. }
  30.  
My question is what the wrong in my solution?

{Thanks slots}
Jul 17 '07 #1
Share this Question
Share on Google+
5 Replies


P: 87
[i]Hello...


After the execution, the outdata.txt should contain:

Sarah_AlSammak@alahliunitedbank.com.bh

What IS the output now?

J
Jul 17 '07 #2

100+
P: 147
Your output statement is all messed up:
Expand|Select|Wrap|Line Numbers
  1. outfile<<"Fname_lname"<<'@'<<"company_name"<<.com<<".country_code"<<endl;
Enclosing something in double-quotes makes it a string literal. That means that it will be output exactly as you typed it. This is not what you want for things like Fname, lname, and company_name.
Similarly, if you enclose a character in single quotes, it will be output exactly as typed. That is what you want for the '@' character.
Anything not enclosed in quotes is an identifier (such as a variable). If the variable exists and is printable, its value will be printed. So if Fname holds the value "Tom", then this line will print out that name:
Expand|Select|Wrap|Line Numbers
  1. cout << Fname;
Notice the lack of quotes?
In your code, the only .com is outside of quotes, so the compiler sees that as an identifier and rejects it because [a] variable names can't start with a period and [b] even if they could, you never defined that variable.

Hope this helps you see the solution.
Jul 18 '07 #3

sicarie
Expert Mod 2.5K+
P: 4,677
My question is: why are you unable to put this in a compiler and then Google whatever error messages that come out, or do like the Posting Guidelines say and ask a specific, pointed question (such as "Why is my output different from what I want, it's giving me ************ and I want ************")?

Anyway, please read this thoroughly, Mods tend to not react well when you do things like ask someone else to compile your code, not use code tags, not use good thread titles, etc...
Jul 18 '07 #4

P: 14
thanks for every body who write a reply
Jul 18 '07 #5

sicarie
Expert Mod 2.5K+
P: 4,677
thanks for every body who write a reply
You're welcome, but please be sure to follow the Posting Guidelines in the future, or you will not be allowed to post.
Jul 18 '07 #6

Post your reply

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