Below is a code that i have created to seperate a string statement. There are no errors but the code will not display the micron or the idustry statement. what do i need to do so that everything will show

#include <iostream>
#include <string>
#include <fstream>
#include <cstdio>
#include <cctype>
#include <iomanip>
#include <cstdlib>


using namespace std;

int main()
{
	string productNumber;

	cout << endl << setw(40) << "ENTER IN PRODUCT NUMBER: ";
	cin >> productNumber;

	string type = productNumber.substr(0,1);
	string buildCode = productNumber.substr(2,3);
	string micron = productNumber.substr(4,5);
	string lenght = productNumber.substr(6,6);
	string endone = productNumber.substr(7,7);
	string endtwo = productNumber.substr(8,8);
	string oring = productNumber.substr(9,9);
	string industry = productNumber.substr(10,10);

	cout << "\n\n\t" << type << micron << industry << endl;

	return 0;
}

thanks! another question: after i fixed the problem, only one the type was outputed and not the micron or industry string

Post your new code and one sample input (a productNumber)

NEW CODE:

#include <iostream>
#include <string>
#include <fstream>
#include <cstdio>
#include <cctype>
#include <iomanip>
#include <cstdlib>  

using namespace std; 

int main()
{	
string productNumber; 	

cout << endl << setw(40) << "ENTER IN PRODUCT NUMBER: ";
cin >> productNumber;

string first = productNumber.substr(0,1);
string buildCode = productNumber.substr(2,2);
string micron = productNumber.substr(4,2);
string lenght = productNumber.substr(6,1);
string endone = productNumber.substr(7,1);
string endtwo = productNumber.substr(8,1);
string oring = productNumber.substr(9,1);
string industry = productNumber.substr(10,1);

cout << "\n\n\t" << type << micron << industry << endl;

return 0;
}

A sample product number is FAP831EHSB

And the output i get is 'F'

Member Avatar for iamthwee

type is not declared?

This shouldn't even compile because you didn't declare "type". You probably meant to type "first" or "buildCode"

Second problem you have is here: string industry = productNumber.substr(10,1); You're sample-input-string only has 10 characters which means position 0-9. 10 is out of bounds.
You probably made a logic-error in this piece of code:

string first = productNumber.substr(0,1); // <-- gets only the first character
string buildCode = productNumber.substr(2,2); // <-- gets the third and fourth.

as you can see you never do anything with the second character.

I fixed the problem but i still cant get anything but the "first" to show up...

string productNumber;

	cout << endl << setw(40) << "ENTER IN PRODUCT NUMBER: ";
	cin >> productNumber;

	string first = productNumber.substr(0,1);
	string buildCode = productNumber.substr(1,2); 
	string micron = productNumber.substr(3,2);
	string lenght = productNumber.substr(5,1);
	string endone = productNumber.substr(6,1);
	string endtwo = productNumber.substr(7,1);
	string oring = productNumber.substr(8,1);
	string industry = productNumber.substr(9,1);

	cout << first << " " << buildCode << " " << micron << " " << length << endl;

	return 0;
}
Member Avatar for iamthwee

length is undeclared.

"length " is not declared.... The rest of the code looks fine.
Are you sure that this is the exact code you're using?

[edit]
That's about the n-th time I crossposted with iamthwee today.

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.