problem with extracting integer from a line

i have this line taken from a txt file:
"#operation=1(create circle and add to picture) name X Y radius." (first line in the file)
why does this code doesnt take the integer 1 and puts it into k?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Circle Circle::CreateCirc(Circle c){
	int k;
	ifstream myfile("cmd.txt");
	if (!myfile.is_open())
		cout<<"Unable to open the requested file "<<endl;
	string line,line2="create circle";
	for (int i=1;i<countrows();i++)
	{
		getline(myfile,line);
		if (line.find(line2)!=string::npos)
		{
	         istringstream ss(line);
			 ss>>k;
			 cout<<k<<endl;
	
		}

	}
	return c;
	
}


instead im getting adress memory...help plz
The read operation on line 13 will fail because the stream reads from the beginning of the line. It fails to read an integer because the first character it finds is the # character.
Last edited on
even when i deleted the '#' it still gives me the same output...
1
2
3
4
5
6
    int n = 0;
    string line = "#operation=1(create circle and add to picture) name X Y radius.";
    istringstream ss(line);
    ss.ignore(100,'='); // ignore up to and including '='
    if (ss >> n)
        cout << "Number is " << n << endl;

Number is 1

thank you very much!
opne more question...how can i promote the pointer to the file to point to the next line??
After the getline(myfile,line); the stream is already positioned at the start of the next line. There isn't anything extra needed.
Topic archived. No new replies allowed.