1. Write a program that read the data from a file name address.txt. Then, right justifies the text in new text file name add.txt. Given the width of the new text file is 70.

2. Write a program that counts and prints the numbers of line and word from a file name address.txt. Use C++ String.

Somebody can help me on this simple VB C++ program?

Recommended Answers

All 9 Replies

never heard of a "VB C++ program".
And no, we're not here to do your homework for you.

never heard of a "VB C++ program".
And no, we're not here to do your homework for you.

VB c++ is visual basic c++ don't ya know?
and yeah u right, but at least show me or gimme some tips on that...coz i'm totally new to it...
anyway, thankz...;)

Member Avatar for iamthwee

Are you allowed to use #include <iomanip.h> ?

VB c++ is visual basic c++ don't ya know?

So which one are you programming in? Visual Basic or C++? or are you attempting to learn 2 languages at the same time?

As I understand it, Visual Basic is a language, C is a language, and C++ is a language, but VC++ is an Integrated Development Environment proprietary to Microsoft. However, VBC++ doesn't fit any of those criteria. If you are using the C++ language then you would read a file using either an ifstream or an fstream in ios::in mode and you would write to a file using either an ofstream or an fstream in ios::out mode. Streams to use with a file are available by including the fstream header file. Justification of output text can be done using ostream manipulators and such, some of which are in the iomanip header file. You can count the number of lines by counting the number of newline char found in the file and you can make an approximation of the number of words by counting the number of whitespace characters (space, tab, newline, etc) in a file. Printing the values in terms of the number of lines and words should be straightforward.

Are you allowed to use #include <iomanip.h> ?

Yeah! it's like:


#include <iomanip>
using namespace std;
...

So which one are you programming in? Visual Basic or C++? or are you attempting to learn 2 languages at the same time?

it's something like this:

#include <iostream>
#include <fstream>
//#include <string>

using namespace std;

int main () {
  char filename[17],name[70], title[70];
  

  cout << "Enter your name: ";
  cin.getline (name,70);

  cout << "Enter your favourite movie: ";
  cin.getline (title,70);

  cout << name << "'s favourite movie is " << title<<endl;
 
  cout<<"enter filename to save: \n";
  cin>>filename;
 
  ofstream outfile(filename,ios::out);
 
  outfile<<name<<" "<<title;
  outfile.close();
  
  return 0;

}

ofstream is a dedicated fstream. It can only be used in the ios::out mode, so you don't have to explicitly state ios::out when declaring an ofstream object.

ofstreams can be used with the same syntax that you use with cout. ostreams, and therefore ofstreams, have a member function called width() that can be used to set the width of the very next output field. If the output doesn't completely fill the field the output is automatically right justified and padded on the left with space characters as needed. The width of the next field is passed to width() as an argument. Thus cout.width(4); says the very next output statement will be 4 char wide. If the very next output is the int 7, then the output will be 3 space characters and the digit 7.

commented: Nice Post~~SpS +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.