Getting "'string' does not name a type" Error

Hello,
I am getting error as below:

NMEA2=GPS.lastNMEA();
exit status 1
‘string’ does not name a type

Below is my full code:

#include <Adafruit_GPS.h>
#include <String.h>
#include <SoftwareSerial.h>

SoftwareSerial myserial(3,2); //This is a serial port where TX[3 port] and RX[2 port] are connected
Adafruit_GPS GPS(&myserial);   //Create the GPS object
string NMEA1;  // Hold the GPS data
string NMEA2;  // Hold the GPS data
char c;

void setup() {
  Serial.begin(115200); //Turn on serial Monitor
  GPS.begin(9600); // Turn on GPS at 9600 Baud rate Speed
  GPS.sendCommand("$PGCMD,33,0*6D"); //Turns off the antenna for garbage value
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);  // Only RMC and GGA will taken into consideration
  delay(1000);
}

void loop() {
  readGPS();
}

void readGPS(){
  while(!GPS.newNMEAreceived()){
    c=GPS.read();
  }
  GPS.parse(GPS.lastNMEA());
  NMEA1=GPS.lastNMEA();

  while(!GPS.newNMEAreceived()){
    c=GPS.read();
  }
  GPS.parse(GPS.lastNMEA());
  NMEA2=GPS.lastNMEA();
  Serial.println(NMEA1);
  Serial.println(NMEA2);
}

Can you please help…

Thanks-
Pokhraj

Try String instead.

Better still, don't use String at all.

If I want to use string what will I do?
Please advice…

Pokhraj

Like AWOL said, use String.

Do you see the difference between what you have "string" and what you were told "String"?

If I want to use string what will I do?

Step 1: Understand the difference between a string and a String. Step 2: Use a string - a NULL terminated array of chars - whenever you like. No header file needed.

You are NOT programming a PC. Drop the bad habits.

Ohhhh..

Got it.... It works...

Thanks a lot..

Hello,

I am a beginner. Just to know the below details:

As per the above Sketch I posted earlier, I called the below function to get only RMC and GGA format...

GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);

======== But I am getting all the other formats also like below;

$GPRMC,, $GPVTG,,,,,,,,, $GPRMC,, $GPVTG,, $GPGGA,, $GPGSV,

$GPGLL,

Can anyone suggest and provide help please..

Thanks- Pokhraj