plz i realy do need help:D

i only want to read the contents of a text file but i dont know how:(

ex:
test.txt

how to read its contents

What are you going to do with the contents of the file? How big is it?

the contents of the file is
$GPGLL,4157.343,N,08340.197,W,154648,A*31

it is a log file for GPS reciver i have to read them first in console then i have to encode them

Get yourself an Introduction To c++ book and start reading/studying from page #1. If you don't know how to do simple file stuff then there is no way you will be able to encode a file. Read the Read Me threads at the top of this board for a wealth of information you need to learn.

i tried to open the text file by this code but the contents are changed to ==> 000000 :S
as the contents of the file are
$GPGLL,4157.343,N,08340.197,W,154648,A*31

// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
  ifstream myfile;
  myfile.read ("C:\test.txt", ios::in );
  cout<<myfile;
  return 0;
}

can any one tell me where am i wrong plz

>>can any one tell me where am i wrong plz
Yes, you failed to use code tags when you posted here :)

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
  std::string line;
  ifstream myfile("C:\test.txt");
  // now read the first line of the file
  getline(myfile, line);
  // display the line on the screen
  cout << line << "\n";
  // make the program wait for keypress so you can see the above output
  cin.get();
  return 0;
}
#include <iostream>
#include <string>
#include <algorithm>
#include <ctype.h>
using namespace std;
int linefeed = 10;       // linefeed in ASCII
int carriageReturn = 13; // carriage return in ASCII
// The serial port
int sensorValue = 0;     // the value from the sensor
float latitude = 0.0;    // the latitude reading in degrees
// north or south?
float longitude = 0.0;   // the longitude reading in degrees
// east or west?
void main()
{
string x = "$GPGLL,4157.343,N,08340.197,W,154648,A*31";
cout<< x;
//cin>>x;
}

thanks all for your fast help i have succeded in the first time in my life with C++ :D but i only want to know something else:)
if i want to check that the string contains $GPGLL for example knowing that each substrings ends with "," how can i do that :D;)

thanks all for your fast help i have succeded in the first time in my life with C++

Congrats ;)

if i want to check that the string contains $GPGLL

Use strstr function after copying the file contents to a buffer/string.

>void main()

main returns int.

>i want to check that the string contains $GPGLL

Use std::string::find.

>knowing that each substrings ends with ","

Use std::string::find_first_of.

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.