[solved]-sd-card module doesn't work with arduino mega2560.

I connect the sd-card module pins with arduino mega:
cs → 53
mosi → 51
sck ->52
miso ->50
GND → GND
5V → 5V
the compiler doesn’t display any errors…and I uploaded the code.Everything is okay,but when I open the serial monitor this message appears
//error opening file…
This is the code:

#include <SD.h>
#include <SPI.h>

int CS_PIN = 53;

File file;

void setup()
{

 Serial.begin(9600);

 initializeSD();
 createFile("test.txt");
 writeToFile("This is sample text!");
 closeFile();

 openFile("prefs.txt");
 Serial.println(readLine());
 Serial.println(readLine());
 closeFile();
}

void loop()
{
}

void initializeSD()
{
 Serial.println("Initializing SD card...");
 pinMode(CS_PIN, OUTPUT);

 if (SD.begin())
 {
   Serial.println("SD card is ready to use.");
 } else
 {
   Serial.println("SD card initialization failed");
   return;
 }
}

int createFile(char filename[])
{
 file = SD.open(filename, FILE_WRITE);

 if (file)
 {
   Serial.println("File created successfully.");
   return 1;
 } else
 {
   Serial.println("Error while creating file.");
   return 0;
 }
}

int writeToFile(char text[])
{
 if (file)
 {
   file.println(text);
   Serial.println("Writing to file: ");
   Serial.println(text);
   return 1;
 } else
 {
   Serial.println("Couldn't write to file");
   return 0;
 }
}

void closeFile()
{
 if (file)
 {
   file.close();
   Serial.println("File closed");
 }
}

int openFile(char filename[])
{
 file = SD.open(filename);
 if (file)
 {
   Serial.println("File opened with success!");
   return 1;
 } else
 {
   Serial.println("Error opening file...");
   return 0;
 }
}

String readLine()
{
 String received = "";
 char ch;
 while (file.available())
 {
   ch = file.read();
   if (ch == '\n')
   {
     return String(received);
   }
   else
   {
     received += ch;
   }
 }
 return "";
}

The image of serial monitor is in 2.png.
Can you help me please?! Thank you.

Please use code tags when posting blocks of code. Use the button which looks like </> in the top left of the post editor to insert code tags.

kinda:
and I connect the aux female(data pin)

The “aux female” of what? Did you also connect the gnd to the mystery device?

kinda:
I connect the aux female(data pin) to 7 on arduino mega board

Yet in the code you posted you have:

tmrpcm.speakerPin=10;

And in the documentation for the TMRpcm library it states:

audio.speakerPin = 11; set to 5,6,11 or 46 for Mega, 9 for Uno, Nano, etc.

add:

  pinMode(cs, OUTPUT);

to void setup()

Yet in the code you posted you have:

tmrpcm.speakerPin=10;

And in the documentation for the TMRpcm library it states: [/quote]

Thank you very much. But the second code still doesn't work.

Maybe:

if (SD.begin(CS_PIN)) ...