954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Substring Error ???????

Im sure i have a syntax issue or just not doing something right as i am new to c++.. i am generating an error code in my program ... here is my code

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <string>
#include <string.h>

using namespace std;

int main(int argc, char *argv[])
{

// Opens the Text File in is my "cin" in essence
ifstream in ("C:\\Documents and Settings\\HP_Administrator\\Desktop\\test.txt");

//both arrays in which i will place the text from the text file. "registers" will get the first 8 lines of numbers and memory will get the remaining lines of numbers
 int registers[7];
 int memory[4000];
 int i;
 int x;
 string s;
 string string;
 
 
 
// read registers until eight integers are read
    i = 0;
    while (getline(in, s)) {
          if (stringstream( s ) >> registers[i]) i++;
          if (i == 8) break;
          }
          
          // read memory until the end of file
          i = 0;
          while (getline ( in, s )) {
                if (stringstream( s ) >> memory[i]) i++;
                }
                
                cout << "(:----------REGISTERS----------:)" << endl;
                cout << " " << endl;
                for (i=0; i<8; i++)
                cout << "Registers   : " << setfill ('0') << setw (6) << registers[i] << "          -:)" << endl;
                cout << " " << endl; 
                cout << "(:-----------MEMORY------------:)" << endl;
                cout << " " << endl;
                for(i=0; i<14; i++)
                
                cout << "Memory Dump : " << setfill ('0') << setw (6) << memory[i] << "          -:)" << endl;
                cout << " " << endl;
                cout << "(:-----------------------------:)" << endl;

if (memory[i].substr(0,4)=="0000")
(
cout << "See Groups 3 & 4 " << endl;
) 
       
                in.close();


the error generated is as follows:

in function 'int main(int, char**):'
'substr' has not been declared
request for member of non aggregated type before '(' token


any help is greatly appreciated thank you very much

swuwarrior
Newbie Poster
11 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

substr() isn't a member function of an int. An int is a primitive, not a class. Also, you can't really call a substring on an integer.

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

>>if (memory[i].substr(0,4)=="0000")

memory is an array of integers which of course don't have methods.
[edit]^^^ what Shawn said[/edit]

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

so i should have a string array instead

swuwarrior
Newbie Poster
11 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

It depends on what you want to do with that particular operation. You might need a string or you could just use modulus.

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You