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

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

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

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.