0

ca anyone help me... i am having a problem of my c++ code.. im still a begineer in c++ and i want to creat a program that searches and input an ID number and reading the whole line..this is my sample txtfile

Record2.txt

101,Kirviepalencia,500.00
102,ALmond Olilang,700.00
103,Krishna Laguardia,200.00
104,Carl Kabalyero.300.00

Output:
Enter ID: 101
101,Kirviepalencia,500.00
Enter ID: 104
104,Carl Kabalyero.300.00

i included my program here.. hope anyone can help me here..thanks in advance..

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

int main(int argc, char *argv[])
{
  ifstream kirviealmond ("Record2.txt");

  if(!kirviealmond) {
    cout << "Cannot open input file.\n";
    return 0;
  }

  char str[255];
  char ble[255];

  while(kirviealmond) {
    cout<<"enter id number:";
    cin>>str,ble;
    kirviealmond.getline(str, 255),(ble,255);  // delim defaults to '\n'
    if(kirviealmond) cout << str<<ble<< endl;
  }
  //else if


  kirviealmond.close();

  return 0;
}
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by kirviepalencia
0

Hello,

This is my first post :)

Try this:

int main()
{
	string sFilePath("C:\\Documents and Settings\\Administrator\\Desktop\\Support\\MyFile.txt");
	string dLine(""), input("");
	ifstream inFile(sFilePath.c_str());
	cin >> input;
        input += ",";
	while(!inFile.eof())
	{
		getline(inFile, dLine);
		if(dLine.find(input) != dLine.npos)
		{
			cout << "Found Text: \t";
			cout << dLine << "\n\n";
		}
	}
	return(0);
}

Edited by mayyubiradar: code correction

0

omg... thank you so much.. at last my problems are solve.. you are a great programmer hehe.. tnx again..^_^

This topic has been dead for over six months. 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.