visual c++

Hello, I'm new to Visual C++. I'm trying to make a simple program which calculates the amount of letters in the word, so as I understand I need to find out the size of string. However, neither string.size() nor string.length() seems to work here. Do I have to include something or is everything different here?

1
2
3
4
				 String^ i;
				 i=textBox2->Text;
				 textBox1 -> Text= i;
				 int a = i.Size();
What do you mean string.size() / string.length() doesn't work? Can you be more specific. If you posted more code I am more likely to be able to assist you better. Do you mean it is not returning the size you expected? Have you tried debugging?
Apparently, I needed to use x -> Length; to get the result I needed. As I said, I'm very new to Visual Studio and pretty new to C++ so I might be wrong somewhere. But if it works then I'm OK with that
String ^ i; is not a C++ construction. It is a CLR construction that is it is construction of C++/CLI.. Try to use i->Length. For example

1
2
3
4
5
6
7
8
9
10
11
12
13
#include "stdafx.h"
#include <iostream>

using namespace System;

int _tmain(int argc, _TCHAR* argv[])
{
	String ^s = gcnew String( "It is a test" );

	std::cout << "The string length = " << s->Length << std::endl;

	return 0;
}


The output is

The string length = 12
Topic archived. No new replies allowed.