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


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

Enter ID: 101
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:";
    kirviealmond.getline(str, 255),(ble,255);  // delim defaults to '\n'
    if(kirviealmond) cout << str<<ble<< endl;
  //else if


  return 0;


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 += ",";
		getline(inFile, dLine);
		if(dLine.find(input) != dLine.npos)
			cout << "Found Text: \t";
			cout << dLine << "\n\n";

Edited 6 Years Ago by mayyubiradar: code correction

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

This article has been dead for over six months. Start a new discussion instead.