wrong reading.

wht I want is name and surname=burcin erek number=783389
but output name and surname=burcin number=erek
it is so funny but no solution.

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>

using namespace std;

void file_read()
{
     string name1;
     string numb1;
     ifstream f("file1.txt");
     f>>name1>>numb1;
     cout << "name and surname=" << name1 << "\n number=" << numb1<<"\n";
}

void file_write()
{
string nam="burcin erek";
string numb="783389";

ofstream f("file1.txt");
f << nam  <<" " << numb;
}


int main(int argc, char *argv[])
{
    file_write();
    file_read();
    system("PAUSE");
    return EXIT_SUCCESS;
}

Please correct the code tags.

>> operator reads until the first whitespace character. So when you are reading the file which has "burcin eric 783389" with the following code

f>>name1>>numb1;

name1 gets burcin and numb1 gets erec.

it means that there is no space between burcin erek
i did like burcin.erek it works.
thanks

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.