Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi...
I hope you don't get confused about the question.
What i meant is that i have a const variable that have string and int value in it and to make it, i used sstream.
Here is my code :
C++
const std::string ERROR1002 = SSTR( "\033[01;31mERROR 1002 : You must insert a value between 001 and " ) +SSTR( MAX_NODE )+SSTR( "!\033[0m" )+SSTR( "\n\033[01;33mYou have inserted : " );

As you see it contains MAX_NODE in it that is an integer variable and what i need is, how to create it that it change the MAX_NODE to string type because i need to use it in a constructor and because of that I'm in trouble.

Any thoughts?
Posted
Comments
Leo Chapiro 9-Sep-15 9:03am    
But your variable contains already MAX_NODE as string thanks to macro SSTR: #define SSTR( x ) dynamic_cast< std::ostringstream & >( \
( std::ostringstream() << std::dec << x ) ).str() ?
I don't understand what is the problem ?
JENOVA_SHINRA 9-Sep-15 9:18am    
This is my problem :
SO << "\n" << error.ERROR(ERROR1002) << "\033[4m" << NUM_NODE << "\n\033[0m";
as you see i used ERROR1002 that contains both string an integer but The ERROR() has been created like this :
std::string ERROR(char*) const;
so the ERROR() only can get string variables not something like ERROR1002.
It have to be exactly std::string.
I wanted to know if there is a way to create another variable to put the ERROR1002 in the new variable?
i have tried something like it but it didn't work.
Sergey Alexandrovich Kryukov 9-Sep-15 9:13am    
No, I'm not confused, you are, otherwise you would not formulate the problem the way it does not make sense. There is no such concept as "variable return".

Your mistake is to try to work with strings representing data, instead of working with data itself. String does not "contain int", it contains only characters which you are bound to parse to extract data. Wrong approach.

—SA
Richard MacCutchan 9-Sep-15 10:23am    
Use a ostringstream object and the stream insertion operator << to build your string.
Richard MacCutchan 9-Sep-15 10:42am    
You could also use the Stringizing Operator (#).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900