Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can someone maybe help me with converting this C# code into C++

Here is the C# code:
[CODE]

I dont know what should i use instead of var and instead of new string function, so i would realy need help with thath.
Posted

1) You just need to use explicit variable declarations instead of var.
ie.int maxLines = height + depth; instead of var maxLines...
2) From what I see you doing, you are padding strings, you can try: Program with Padding a string[^] as an example of how to approach this.
 
Share this answer
 
Comments
HypoXxX 29-Oct-12 16:24pm    
Hmmm, dont realy understand the second thing. On how to change thath new string can you give me some example or somthing?
Use int (or whatever type it is) instead of var. Use std::string[^] for strings. Use printf()[^], or preferably, cout[^] instead of Console.Write(). etc ...
 
Share this answer
 
Comments
HypoXxX 29-Oct-12 16:38pm    
Uhm can you give me example of this std::string how i use it on this project?
Richard MacCutchan 30-Oct-12 4:32am    
Just follow the links to the documentation.
Instead of var, you could just use int (in this case).
new String (' ') can be replaced by " ".

It seems you're a beginner. I hope you're not lifting some's C# code and passing it off as your own C++ work. :(

/ravi
 
Share this answer
 
In your sample, you can replace instances of 'var' with int - since that's all they appear to hold.

As for the string initializations, they're just setting the string to contain the same character a number of times, right?

You could make your own function that filled or created them. Here's one to just set them - your code never hangs onto them - it just passes them to conole.write.

So, make sure you have a std:string object first, then pass it to this function.

C++
void setString(string &input, char newChar, int reps)
{
    input = "";
    int i;
    for  (i=0; i<reps; i++)
        input = input + newChar;
}



A quick sample:
C++
#include <iostream>
using namespace std;


void setString(string &input, char newChar, int reps)
{
    input = "";
    int i;
    for  (i=0; i<reps; i++)
        input = input + newChar;
}

int main()
{
    string testMe;

    setString(testMe, '*', 10);
    cout << testMe << endl;

    setString(testMe, '-', 10);
    cout << testMe << endl;

}


Output:
**********
----------
 
Share this answer
 

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