2 Replies - 2702 Views - Last Post: 23 June 2011 - 06:34 AM Rate Topic: -----

#1 martinmax3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 23-June 11

Using namespace std syntax error.

Posted 23 June 2011 - 06:16 AM

I am using Borland C++. Instead of
char ime[64], kod[64], talant[64];

I had
char *ime,*kod,*talant;

and I also didn't have namespace std. But when I runned the program I could not input "ime". It just printed on the screen the next cout and then I could type in for it. So they told me to change the char declaration to that. It started givign me linker error and a warning when trying to run the program, so I looked it up and found something about namespace std. I tried adding it now, but it gives syntax error. And I think I've used that one before when I copy/pasted Hello World to see if compiler works and it didnd't give me error then.

#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <iomanip.h>
using namespace std;
class tal
 {
  public:
  char ime[64], kod[64], talant[64];
  int tochki;
  public:
  void vhod();
  void izhod();
 }p[300];
int n;
char *swap;
void tal::vhod()
 {
  cout<<"Trite imena: ";
  cin.getline(ime,46);
  cout<<"Kod: ";
  cin.getline(kod,11);
  cout<<"Talant: ";
  cin.getline(talant,21);
  cout<<"Tochki: ";
  cin>>tochki;
  cout<<endl;
 };
void tal::izhod()
 {
  char *str1,*str2,*str3,str4,*str5,*str6,*str7,*str8;
  int found=1;
  for(char *where=ime; *where!=' ';++where)found+=1;
  strncpy(str1,ime,found);
  str1 += '.\n';
  for(*where=ime[found]; *where!=' ';++where)found+=1;
  do
   {
    str2 +=ime[found];
    found+=1;
   }
  while(ime[found]!='\n');
  str2 +='\n';
  strncpy(str3,kod,3);
  str4=kod[3];
  switch(str4)
     {
      case 1:
       str5="Sofiq";
      break;

      case 2:
       str5="Plovdiv";
      break;

      case 3:
       str5="Varna";
      break;

      case 4:
       str5="Burgas";
      break;

      case 5:
       str5="Ruse";
      break;

      case 6:
       str5="Blagoevgrad";
      break;
     };
  strncpy(str6,(kod+4),2);
  strncpy(str7,(kod+6),2);
  strncpy(str8,(kod+8),2);
  cout<<str1<<str2<<", "<<str3<<", "<<str5<<", "<<talant<<", "<<tochki<<", "<<str6<<"."<<str7<<"."<<str8<<endl;
 }
int main()
 {
  cout<<"Broi uchastnici: ";
  cin>>n;
  cout<<endl;
  if(n<1 || n>500)
   {
    cout<<"Greshen broi uchastnici!"<<endl;
    return 1;
   }
  for(int i=0;i<n;i++)
   { 
    p[i].vhod();
   }
  /*for(i=0;i<n;i++)
   {
    for (int j=n-1;j>=i;j--)
     {
      if(strcmp(p[j-1].ime,p[j].ime)>0)
       {
	swap=p[j-1].ime;
        p[j-1].ime=p[j].ime;
        p[j].ime=swap;
       };
     };
   } */
  for(i=0;i<n;i++)p[i].izhod();
  return 0;
 }


Edit: Sorry, I think I found the error. My compiler is from 1991 or so. It's version 3.1. o.0

This post has been edited by martinmax3: 23 June 2011 - 06:19 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Using namespace std syntax error.

#2 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 615
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Using namespace std syntax error.

Posted 23 June 2011 - 06:24 AM

iostream.h is an old depreciated header, instead, you should use iostream. Same goes with the other headers, they should be as follows.

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>


Other errors include here, in which you're trying to use the pointer "where" when it hasn't been declared in the correct scope. Also, you're trying to assign where (char*) to ime[found] (char), so you're getting a conversion error. Use the "address of" operator if you want to fix that error (i.e. where=&ime[found]).

for(where=ime[found]; *where!=' ';++where)


Same with this, i is not declared.

for(i=0;i<n;i++)p[i].izhod();


You should use a newer compiler if your current compiler wasn't complaining about the headers you used.

This post has been edited by Aphex19: 23 June 2011 - 06:26 AM

Was This Post Helpful? 1
  • +
  • -

#3 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Using namespace std syntax error.

Posted 23 June 2011 - 06:34 AM

There are a number of free modern compilers out there.

If you like having an IDE (fancy graphical front end/editor) then you have a couple of choices:

People seem to like Visual C++ (express) which requires you to register but is free otherwise.

Another popular one is Code::Blocks

Then there is wxDev-C++ which is a reboot of the long dead Dev-C++ which I suggest you avoid since it is also very old and tends to have minor *issues* which will probably never be fixed at this point. -- but wxDev-C++ is alive and well and comes with is great for working with the wxWidgets library for GUI programs.


If you are comfortable with the command line you can just get a programmer's text editor such as:
Programmer's Notepad (what I use)
Notepad++
SciTE (which is actually a demo program for using the scintilla editor library - Scintilla Text Editor -- so if you ever want to write your own text editor here is good place to start!)

Then you can download a compiler:
The Microsoft Windows SDK comes with cl.exe which is the compiler used by Visual C++
You can download a copy of MinGW (I prefer to use a more modern distro then the one available on the MinGW website so I use the nuwen.net distro which also comes pre-loaded with a number of useful libraries)

Basically my point is: There is no compelling reason to stick with an ancient outdated compiler!
Was This Post Helpful? 3
  • +
  • -

Page 1 of 1