Joe
Joe

Reputation: 79

Why are all cout's and cin's "undeclared identifiers

In my main.cpp all of my cout's and cin's have errors.

/**
* Description: This program demonstrates a very basic String class.  It creates
* a few String objects and sends messages to (i.e., calls methods on)
* those objects.
*
*/
//#include <iostream>
#include "mystring.h"
//using namespace std;

/* Function Prototypes */

void Display(const String &str1, const String &str2, const String &str3);


/*************************** Main Program **************************/

int main()
{
  String str1, str2, str3;   // Some string objects.
  char s[100];               // Used for input.

  // Print out their initial values...

 cout << "Initial values:" << endl;
 Display(str1, str2, str3);

My main.cpp cannot not be changed, so my question is, how can I fix this error, what do I have to add to my header file and implementation file?

Upvotes: 1

Views: 17988

Answers (2)

Shafik Yaghmour
Shafik Yaghmour

Reputation: 158469

You have iostream header commented out here:

//#include <iostream>

You also need to add std::, this:

cout << "Initial values:" << endl;

should be:

std::cout << "Initial values:" << std::endl;

I see that you have using namespace std; commented out. I would advise against using namespace std;, it may save you some typing but it is considered bad practice and can cause problem later on.

Upvotes: 4

taocp
taocp

Reputation: 23634

In my main.cpp all of my cout's and cin's have errors.

You simply need to include <iostream> header file, and use std with cout and cin:

#include <iostream>
//^^
int main()
{
    std::cout << "Initial values: "<< std::endl;
    //^^
}

Upvotes: 5

Related Questions