How to change the default C++ file extension in Eclipse CDT when creating a new file?

元气小坏坏 提交于 2019-12-01 06:34:40

See Window > Preferences > C/C++ > Code Style > Name Style > Files > C++ Source File > Suffix

I've digged Eclipse CDT code and found a solution:

append

nameStyle.cpp.source.suffix=.cc

to

<workspace location>/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.ui.prefs

Here is how I did it:

  1. "Got started with CDT development", checked out org.eclipse.cdt.ui
  2. Opened src/org.eclipse.cdt.internal.ui.wizards.filewizard/NewSourceFileGenerator.java (actually I searched for the ".cpp" pattern and found it)
  3. "public static String generateHeaderFileNameFromClass(String className)" tells us about PreferenceConstants.NAME_STYLE_CPP_HEADER_PREFIX
  4. We jump to PreferenceConstants.java and obtain the IPreferencesService path: nameStyle.cpp.source.prefix
  5. This article nicely explains where the prefs are stored

The bug mentioned by Ogre Psalm33 was fixed in 2013.

The location in Eclipse 4.4 is:

Window > Preferences > C/C++ > Code Style > Name Style > Files

Related: Make Eclipse treat .h file as C++?

Answer: it currently can't be done in Eclipse 3.6 (Helios) with CDT 7.0.0. See Eclipse Bugzilla entry. Apparently it's logged as a bug/missing feature, but nobody's assigned to work on it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!