0

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;
}

Edited by mike_2000_17: Fixed formatting

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by burcin erek
0

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.

Edited by vidit_X: n/a

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.